Storyboard使用TableView进行页面跳转传值

来源:互联网 发布:淘宝怎么在百度推广 编辑:程序博客网 时间:2024/05/17 02:03

场景

StoryBoard中

A 界面 TableView

B界面 明细页面

A & B通过Cell的Section Action事件进行页面跳转。


Controller中

table delegate

?
1
2
3
4
5
6
7
8
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
       
}
     
override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
         
        return indexPath
}


storyboard页面跳转回调

?
1
2
3
4
5
6
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

0 0
原创粉丝点击