0

I'm pushing to another WKInterfaceController when a row is selected but I can't seem to pass the rowIndex as context for my new controller which I would like to do.

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

This code gives the error

incompatible integer to pointer conversion sending NSInteger: implicit conversion of 'NSInteger' (aka 'int') to 'id' is disallowed with ARC.

I can change my context to nil and the build succeeds but of course then I have no context. I've taken a look at the class documentation which has helped me a lot so far and similar questions on stackoverflow but I'm stuck not knowing how to write this. Thanks for any help.

Kampai
  • 22,848
  • 21
  • 95
  • 95
Mr. Slowpoke
  • 21
  • 1
  • 2

3 Answers3

3

The error

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

Clearly says that you are passing NSInteger as a parameter where as method it suppose to be id.

In below line second parameter required id object.

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

With the help of @fabian789, It is clear now that in WKInterfaceController Class Reference

that method required id object as second parameter.

enter image description here

To pass an integer there, you can convert your NSInteger to an NSNumber and pass in a second parameter.

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

You can then in the target controller get the row index by calling integerValue on the context.

Kampai
  • 22,848
  • 21
  • 95
  • 95
  • 1
    Yes! This did the trick, thanks very much. I NSLog'd my context in the new interface controller and got the values expected. Yay. – Mr. Slowpoke Dec 23 '14 at 08:46
  • FYI `-pushControllerWithName:context:` is a method of `WKInterfaceController` and can not be changed. [Docs](https://developer.apple.com/library/prerelease/ios/documentation/WatchKit/Reference/WKInterfaceController_class/index.html#//apple_ref/occ/instm/WKInterfaceController/pushControllerWithName:context:). – fabian789 Dec 23 '14 at 10:44
  • I updated your answer, hope you don't mind! – fabian789 Dec 23 '14 at 10:47
  • Sure any time. Its appreciating. – Kampai Dec 23 '14 at 10:48
  • Rashad provided the same solution 3 hours ago and the OP said it didn't work, so how is it that this answer is suddenly acceptable? – Droppy Dec 23 '14 at 10:51
  • @Droppy: I don't know about OP's intention and what his getting. It's not in my hand. – Kampai Dec 23 '14 at 10:55
  • How to access rowValue in ZoomPokeController ? – Aadil Keshwani Feb 07 '15 at 20:48
1

You are sending wrong parameter type. Cast the rowIndex to int Try this:

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

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

Hope this help... :)

Rashad
  • 11,057
  • 4
  • 45
  • 73
  • Thanks for the response. replacing my code with this but I still get two errors with that one. Implicit conversion of int to id is disallowed with ARC and incompatible integer to pointer conversion sending 'int' to parameter of type 'id'. If I scroll up to - (void)awakeWithContext:(id)context { and switch (id) to (int) or (NSInteger) I also get an error. I may have found somebody else's code to use as an example at https://github.com/leiyong316/AppleWatchDemo/blob/master/TestWatch%20WatchKit%20Extension/InterfaceController.m so I'll try studying that. Thank you. – Mr. Slowpoke Dec 23 '14 at 07:33
0

The Error clearly States what you are doing wrong, You are Sending an NSInteger type to only an integer, try declaring the context parameter as an NSInteger or use it like this,

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

but the earlier method is more effective

Rashad
  • 11,057
  • 4
  • 45
  • 73
Geet
  • 2,427
  • 2
  • 21
  • 39