我有一个WKInterfaceController,我添加了一个表格如下:
// .h
@interface InterfaceController : WKInterfaceController
@property (weak, nonatomic) IBOutlet WKInterfaceTable *table;
@end
// .m
- (void)table:(WKInterfaceTable *)table didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"did select");
}
- (void)table:(WKInterfaceTable *)table
didSelectRowAtIndex:(NSInteger)rowIndex{
NSLog(@"did select new");
}然而,这两种方法都没有被调用。我无法为WKInterfaceTable找到任何协议声明,也无法在表上找到任何委托属性。
这里有我遗漏的东西吗?
发布于 2015-05-14 08:18:33
我发现这个方法从来没有被调用过,因为我已经将一个segue设置为在Interface上选择行时被触发。
似乎通过没有委托和表协议,一旦设置了委托,它就会阻止调用didSelectRow方法。
发布于 2015-05-19 09:26:59
在苹果的WKInterfaceController文档中,它指出,如果您没有任何操作或索引,那么调用的方法是:- table:didSelectRowAtIndex:
如果使用segues,那么调用的方法如下:
按钮:- contextForSegueWithIdentifier:
表:- contextForSegueWithIdentifier:inTable:rowIndex:
发布于 2018-11-20 12:45:18
Swift 4
下面是在REST/JSON实现中选择WKInterfacetable行的示例。
创建数组类的上下文属性实例,而不是使用self.pushController。
override func table(_ table: WKInterfaceTable, didSelectRowAt rowIndex: Int) {
let message = messageObjects[rowIndex]
presentController(withName: "MessageView", context: message)
}https://stackoverflow.com/questions/30232246
复制相似问题