uinavigationcontroller 在弹出时更新之前的视图
我有一个 UINavigationController,我从 Level1 转到 Level2,在其中选择行/项目;然后我使用后退按钮返回 - 但是 - 在我的级别 1 中,我显示了默认选择(我通过转到级别 2 并选择其他内容来更改它) - 而我的级别 1 根本没有改变,所以我猜想viewDidLoad 不再被调用...我如何强制它重新加载?
非常感谢
干杯 吉比
编辑1: 我知道你是对的,但它不起作用 - 我问自己是否它与可重复使用单元的所有内容有关,因此它不会重新加载......这可能吗?还有更多想法
编辑2: 事实上,它不起作用意味着我将所有代码(事实上我将其移动)从 didLoad 复制到了 viewWillAppear - 这是正确的做法吗? 或者应该尝试在正确的位置更新我的 nsmutablearray ? 谢谢。干杯
编辑3:事实上,在我的代码中添加更多标志/消息来了解发生了什么,虽然在重新显示时调用 viewWillAppear,但可见单元格并未“重新绘制/刷新”。因此,如果我向下滚动然后向上滚动,神奇地,更改会起作用并出现,但我希望这种情况从一开始就发生。任何想法请帮忙。谢谢
I have a UINavigationController and I go from Level1 to Level2 where I select a row/item ; and then I go back using the back button - BUT - in my level 1 I was displaying a default selection (which I changed by going to Level2 and select something else) - and my level 1 does not change at all so I guess that the viewDidLoad is not called again... how do I force it to reload?
Thanks a lot
Cheers
geebee
EDIT1:
i know you are right but it didn't work - I was aksing myself if it has to do with all the stuff about re-usable cells and so it does not reload... is that possible? any more ideas
EDIT2:
in fact, it didn't work means that I copied all the code (I moved it in fact) from didLoad to viewWillAppear - was that the right thing to do?
or should have tried to update my nsmutablearray at the right place?
Thanks. Cheers
edit 3: in fact, putting some more flags/messages in my code to understand what is going on, although viewWillAppear is called when re-displayed, the visible cells are not "repainted/refreshed". as such if I scroll down then up, magically the changes are working and appear BUT I would like this to happen right from the start. any idea please help. thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
-viewDidLoad
在 UIViewController 的生命周期内仅被调用一次。它在请求视图控制器的视图后立即调用,例如通过访问其view
属性。因此,在您的情况下,您希望将重新加载代码放在-viewWillAppear:
中。每次显示视图控制器的视图时都会调用此方法。-viewDidLoad
is called only once during the lifetime of a UIViewController. It is called right after the view controller's view is requested, such as by accessing itsview
property. Therefore, in your case you want to put your reloading code in-viewWillAppear:
. This method is called every time your view controller's view is displayed.您可以将更新代码放入控制器的
-viewWillAppear:
方法中You can put your updating code to controller's
-viewWillAppear:
method但是 -viewWillAppear 在 ios 4.3 中没有被调用,它在 ios 5.0 及更高版本中被调用
But -viewWillAppear is not called in ios 4.3, it does get called in ios 5.0 and up