我在第一个界面控制器中有一个表格,当按下一行,模态界面控制器打开时,它包含一个按钮。如何通过按下第二个界面控制器(模态视图)中的按钮删除第一个界面控制器中的一行
我想要按钮删除第一个界面控制器中的行。
这是我的代码:
在第一接口控制器
块引用
// It opens up a modal view (with the context of the tapped row)
override func contextForSegueWithIdentifier(segueIdentifier: String, inTable table: WKInterfaceTable, rowIndex: Int) -> AnyObject? {
var timelineRow = timeline.reverse()
return timelineRow[rowIndex]
}
块引用
这里是我的第二个接口控制器
代码段引用
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
sentContext = (context as? Dictionary)!
sentRow = sentContext
//sentRow contains the context
}
@IBAction func deleteRow() {
var sentRow : [String:String] = ["action":"delete"]
NSNotificationCenter.defaultCenter().postNotificationName("notification_DeleteRow", object: nil, userInfo: sentRow)
dismissController()
}
块引用
我已经通过发送行的索引contextForSegueWithIdentifier。
在第2个接口控制器我已经提取的背景下,把它放在变量
然后我发回用户信息throught的NSNotificationCenter
我的问题:
如何使用从模态控制器发送回来的userInfo来删除点击的行。
我将如何管理通过按下位于(第二IC)的删除按钮
- 我已经在第二接口控制器(在IBAction中)创建了一个NSNotification,并且它将它广播到第一个接口控制器。 - 现在我应该在第一个界面控制器中创建一个删除行的函数,但是如何访问同一行并删除它? – AziCode
您可以在通知的'userInfo'字典中传递自己的信息(例如记录ID)。在您的第一个控制器中,您可以查找该ID并执行正确的删除。 –
你能否给我更多的指示?我应该在第二个界面控制器中创建一个字典吗?我应该在第一个接口控制器的awakeWithContext或者通过NSNotification创建的函数中寻找这个ID吗? – AziCode