2014-12-23 6 views
-1

행을 선택할 때 다른 WKInterfaceController을 밀어 넣었지만 rowIndex을 원하는 새 컨트롤러의 컨텍스트로 전달할 수 없습니다.포인터 변환에 호환되지 않는 정수 nsinteger를 보내는 중

// Push to next controller and pass rowIndex as context 
- (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex { 
    [self pushControllerWithName:(NSString *)@"ZoomPokeController" 
         context:rowIndex]; 
} 

이 코드는 NSInteger를 보내는 포인터 변환 오류를

호환되지 않는 정수를 제공합니다 : ARC으로 허용되지 않는 'ID'에서 'NSInteger'(일명 'INT')의 암시 적 변환을.

context을 nil로 변경하면 빌드가 성공하지만 물론 문맥이 없습니다. 지금까지 많은 도움이되었습니다 클래스 설명서 및 stackoverflow 비슷한 질문을했지만 난이 쓰는 방법을 몰라 붙어 있어요. 어떤 도움을 주셔서 감사합니다.

+0

당신의 메소드에서 [self pushControllerWithName : (NSString *) @ "ZoomPokeController"context : rowIndex]'컨텍스트의 데이터 타입은 무엇입니까? – iHulk

+0

@Mr. Slowpoke는 pushControllerWithName selector의 서명을 공유 할 수 있습니까? –

+0

불명확 한 것으로 결론을 내리는 투표. WKInterfacetable에 대한 링크가 없습니다. 컨텍스트가 무엇인지에 대한 정보가 없습니다. – Droppy

답변

2

...

- (void)table:(WKInterfaceTable *)table didSelectRowAtIndex: (NSInteger) rowIndex { 

    NSNumber *val = [NSNumber numberWithInteger: rowIndex] 
    [self pushControllerWithName:@"ZoomPokeController" context: val]; 
} 

희망이 도움이 오류

"implicit conversion of 'NSInteger' (aka 'int') to 'id' is disallowed with ARC." 

어디 방법으로 그것을 id이라고 가정합니다.

아래의 두 번째 매개 변수는 id 개체가 필요합니다. @의 fabian789의 도움으로

[self pushControllerWithName:(NSString *)@"ZoomPokeController" context: rowIndex]; 

는,이 방법은 두 번째 매개 변수로 id 객체를 요구 WKInterfaceController Class Reference

에서 지금 분명하다.

enter image description here

당신은 당신의 NSInteger NSNumber에 변환하고 두 번째 매개 변수에 전달할 수 있습니다,이 정수를 전달합니다.

- (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex { 
    NSNumber *rowValue = [NSNumber numberWithInteger:rowIndex]; 
    [self pushControllerWithName:@"ZoomPokeController" context: rowValue]; 
} 

그런 다음 대상 컨트롤러 문맥에 integerValue를 호출하여 행 인덱스를 얻을 수 있습니다.

+1

예! 이것은 대단히 감사합니다. NSLog는 새로운 인터페이스 컨트롤러에서 내 컨텍스트를 예상하고 값을 가져 왔습니다. 예. –

+0

FYI'-pushControllerWithName : context :'는'WKInterfaceController'의 한 메소드이며 변경할 수 없습니다. [Docs] (https://developer.apple.com/library/prerelease/ios/documentation/WatchKit/Reference/WKInterfaceController_class/index.html#//apple_ref/occ/instm/WKInterfaceController/pushControllerWithName:context). – fabian789

+0

감사합니다. @ fabian789 - 제 생각은 옳았습니다. – Kampai

0

오류가 분명히 잘못하고있는 일 미국, 당신은 정수에 NSInteger 유형을 보내는, NSInteger로 컨텍스트 매개 변수를 선언하는 시도하거나 다음과 같이 사용,

[self pushControllerWithName:(NSString *)@"ZoomPokeController" context: (int)rowIndex]; 

하지만 이전 방법 더 효과적입니다

1

잘못된 매개 변수 유형을 보내고 있습니다. 이보십시오 rowIndexint에 출연 : 분명히 매개 변수로 NSInteger을 전달하는 것을 말한다 :

+0

응답 해 주셔서 감사합니다. 내 코드를이 코드로 바꾸지 만 여전히 그 코드로 두 가지 오류가 발생합니다.int에서 id 로의 암시 적 변환은 ARC 및 호환되지 않는 정수에서 포인터 변환으로 'int'를 'id'유형의 매개 변수로 보내는 것으로 허용되지 않습니다. awakeWithContext : (id) 컨텍스트 {및 (int) 또는 (NSInteger)로 전환 (id)까지 스크롤하면 오류가 발생합니다. 다른 사람들의 코드가 https://github.com/leiyong316/AppleWatchDemo/blob/master/TestWatch%20WatchKit%20Extension/InterfaceController.m에서 예제로 사용되는 것을 발견했을 수 있으므로이를 시험해 볼 것입니다. 고맙습니다. –

+0

@ Mr.Slowpoke> 내 편집을 참조하십시오. – Rashad