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

本文介绍了如何在Swift中实现Storyboard页面间的TableView跳转,并详细解释了通过Cell的SectionAction事件触发跳转的方法。同时,文章提供了tableDelegate中的willSelectRowAtIndexPath与didSelectRowAtIndexPath函数的具体实现,以及prepareForSegue中传递数据的技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

场景

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

转载于:https://my.oschina.net/lavzchen/blog/484625

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值