确定 UIViewController 第一次出现的时间
在诉诸自定义之前flags 我想和你们核实一下。
是否有内置方法可以在 viewWillAppear:
或 viewWillDisappear:
中确定 UIViewController 是否“新推送”到 UINavigationController 的堆栈上,或者导航控制器是否已弹出另一个查看,揭示这个?我想在视图第一次出现时执行一些一次性代码。因为需要设置 self.bounds 属性,所以 viewDidLoad: 方法不是正确的位置。
我希望用我正在使用的东西得到一些结果 在 viewWillDisappear:
上确定类似的内容,但在第一个 viewWillAppear:
上索引已设置为 1:
[self.navigationController.viewControllers indexOfObject:self]
所以这是一个无用的片段。有什么想法吗?
Before resorting to custom flags I wanted to check this with you people.
Is there a built-in way to determine in viewWillAppear:
or viewWillDisappear:
whether the UIViewController is 'newly pushed' onto a UINavigationController's stack, or whether the navigation controller has popped another view off, revealing this one? I want to execute some one-off code the first time the view appears. Because the self.bounds
property needs to be set, the viewDidLoad:
method is not the right place.
I was hoping to get some results with what I'm using to determine something similar on viewWillDisappear:
, but on the first viewWillAppear:
the index is already set to 1:
[self.navigationController.viewControllers indexOfObject:self]
So this is a useless snippet. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我处理这个问题的方法如下...有一个标志最初设置为 false,当您将子视图控制器推送到导航控制器上时,将此标志设置为 true,如果该标志为 false,则在 viewDidAppear 上没有初始加载如果为 true,那么它将从导航堆栈中弹出的子控制器返回。
The way I handle this is as follows... Have a flag which is initially set to false, when you push a child view controller onto your navigation controller set this flag to true, no on the viewDidAppear if the flag is false then it is the initial load if true then it is being returned to from a child controller popping off the navigation stack.
没有内置的方法来检查它。这是关于您的查询的详细讨论 。
There is no built in way to check it. This is the detail discussionabout your query.