场景
StoryBoard中
A 界面 TableView
B界面 明细页面
A & B通过Cell的Section Action事件进行页面跳转。
Controller中
table delegate
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
}
override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
return indexPath
}
storyboard页面跳转回调
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
destinationCtr = segue.destinationViewController as? FriendViewController
}
通过debug发现prepareForSegue:调用时机在willSelect 和didSelect之间,所以我们可以选择在willSelect方法中获取值,然后在prepareForSegue中传到下个界面,或者在prepareForSegue中获取到下个界面的controller,然后在didSelect中将选中的值赋给controller