0

I'm pushing to another WKInterfaceControllerwhen a row is selected but I can't seem to pass the rowIndexas 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];
}

此代码给出了错误

发送 NSInteger 的不兼容整数到指针转换:ARC 不允许将“NSInteger”(又名“int”)隐式转换为“id”。

我可以将 my 更改context为 nil 并且构建成功,但当然我没有上下文。我已经查看了迄今为止对我有很大帮助的类文档以及关于 stackoverflow 的类似问题,但我不知道如何编写它。谢谢你的帮助。

4

3 回答 3

2

错误

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

清楚地说,你是NSInteger作为参数传递的,它应该是作为方法传递的id

在下面的第二行中,第二个参数是必需id的对象。

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

在@fabian789 的帮助下,现在很清楚在 WKInterfaceController 类参考

该方法需要id对象作为第二个参数。

在此处输入图像描述

要在那里传递一个整数,你可以将你的转换NSInteger为一个NSNumber并传入第二个参数。

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

然后,您可以在目标控制器中通过调用integerValue上下文来获取行索引。

于 2014-12-23T07:56:42.247 回答
1

您发送的参数类型错误。试试rowIndex这个int

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

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

希望这有帮助... :)

于 2014-12-23T07:19:46.813 回答
0

错误清楚地说明了您做错了什么,您正在将 NSInteger 类型发送到仅整数,尝试将上下文参数声明为NSInteger或像这样使用它,

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

但较早的方法更有效

于 2014-12-23T07:16:49.457 回答