ios - WKInterfaceTable 检测选择了哪一行

标签 ios iphone watchkit wkinterfacetable

我只需要检查选择哪一行在WKInterfaceController之间传递数据。这是我的代码,但 NSLog 没有显示任何内容:

- (void)loadTableData {

     NSArray* items = [NSArray arrayWithObjects:@"cell 1 ",@"cell2 ", @"cell 3",@"cell4",nil];

    // Configure the table object (self.todoItems) and get the row controllers.
    [self.myTable setNumberOfRows:items.count withRowType:@"DinoNameRow"];
    NSInteger rowCount = self.myTable.numberOfRows;

    // Iterate over the rows and set the label for each one.
    for (NSInteger i = 0; i < rowCount; i++) {
        // Get the to-do item data.
        NSString* itemText = items[i];

        // Assign the text to the row's label.
        DinoNameRow* row = [self.myTable rowControllerAtIndex:i];
        [row.dinoName setText:itemText];
    }
}
- (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex {

    switch (rowIndex) {
        case 0:
            NSLog(@"ROW 1");
            break;

        default:
            break;
    }
}

最佳答案

确保...

  1. 您的 WKInterfaceTable 通过 IBOutlet 连接到 Storyboard 元素。
  2. 行 Controller 的 rowType 标识符在 Storyboard 中设置:enter image description here
  3. 行 Controller 的类标识符在 Storyboard 中设置: enter image description here
  4. 您已重写正确的 WKInterfaceController 方法:

    override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
    
    }
    

关于ios - WKInterfaceTable 检测选择了哪一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30937095/

相关文章:

ios - 无法从 iPhone 应用程序读取 WatchKit 设置包

ios - 在 watchkit 扩展和 watch app .plist 文件中设置 ATS key

ios - 将 BehaviorRelay 与 Observable 绑定(bind) - RxSwift

ios - 按需加载 UIScrollView

iphone - 我可以使用 UITextFields 中的用户名和密码信息自动登录到 UIWebView 中的网站吗?

ios - 打开 Storyboard 时 Xcode 8 挂起/变得无响应

swift - 根据选择的indexPath加载具体的json message_ids

ios - 使用 Core Data + iCloud 同步时在应用程序和 Today 小部件之间共享数据的正确方法

ios - 通过 xib 文件的类没有标识符为 'searchSegue' 的 segue

iphone - 对数组中的日期进行排序