如何Nav点击后退按钮时刷新之前一个UITableView

  

Just so we're clear: view A is the starting point. User taps something and you slide right to view B. User taps the back button and you're going from B back to A and you want to do something as a result of the 'back' action.

There are three ways to do it (and on neither do you have to go near the navigationController -- these apply to the underlying viewControllers themselves):

  • As dmercredi suggests override viewWillAppear on view controller A so when you're heading back to it, it refreshes itself. Problem is that viewWillAppear is also called when A is called the very first time. So you'll have to set some sort of flag to distinguish between the firstviewWillAppear and any subsequent ones when returning from B.

  • Override viewWillDisappear on view controller B and do your refreshing there. This will only get called when B is about to go away. If there's something on B that goes one level deeper or brings up a modal dialog on top, viewWillDisappear is going to get called so again you'll have to distinguish between the coming and the going.


  • Decouple the various views and use the delegate pattern. View controller A sets itself as a delegate of B and when B updates something it invokes the delegate method, so A is notified of the change and can update whatever it needs to. You can invoke the delegate method any time the user makes a change inside B or override  viewWillDisappear and just do it one time on the way out. 

    老外总结的三种方法,还有个方法,也是个老外说得,把View A的指针直接传给B,然后让B直接去调用这个指针做更新,不太确定是否可行,感觉理论上没什么问题。实践中是用方法三完成的,View controller A将其自身设成B的delegate,当B需要更新A的时候,就调用A的delegate方法,同时在A的delegate方法中视图更新动作[tableView reloadData]. 其中tableView是一个IBOutlet,指向View Controller A中的TableView.网上好多例子都是用的viewWillAppear,但是有人说会有明显刷新的痕迹,就是屏幕会闪一下。目前先用方法三对付,如果后期发现更好的方法再改改。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值