Ril*_*Dev 4 ios swift watchkit wkinterfacetable
我在故事板中创建了一个推送segue从一个 WKInterfaceTableCell到另一个WKInterfaceController(称为DetailInterfaceController).
当我点击该行时, didSelectRowAtIndex未被调用.
有人知道我哪里错了,我怎么能传递字符串?
TableInterfaceController
didSelectRowAtIndexPath print 语句未被调用
@IBOutlet var table: WKInterfaceTable!
var objectsArray = ["1","2","3"]
var object: String!
override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
self.object = self.objectsArray[rowIndex]
print(" object title: \(self.object)")
}
override func contextForSegueWithIdentifier(segueIdentifier: String) -> AnyObject? {
// You may want to set the context's identifier in Interface Builder and check it here to make sure you're returning data at the proper times
// Return data to be accessed in ResultsController
return self.object
}
Run Code Online (Sandbox Code Playgroud)
DetailsInterfaceController
标签未设置
@IBOutlet var label: WKInterfaceLabel!
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
// Make sure data was passed properly and update the label accordingly
if let val: String = context as? String {
self.label.setText(val)
} else {
self.label.setText("")
}
// Configure interface objects here.
}
Run Code Online (Sandbox Code Playgroud)
小智 5
为什么不叫:
table:didSelectRowAtIndex:由于您使用了故事板segue,因此不被调用是正常的.从WKInterfaceController文档:
如果将操作方法连接到storyboard文件中的表,则WatchKit不会调用此方法.
如何传递选定的行数据:
您应该使用contextForSegueWithIdentifier:inTable:rowIndex:返回所选行的上下文:
override func contextForSegueWithIdentifier(segueIdentifier: String, inTable table: WKInterfaceTable, rowIndex: Int) -> AnyObject? {
if segueIdentifier == "someSegueIdentifier" {
return objectsArray[rowIndex]
}
return nil
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
621 次 |
| 最近记录: |