简体   繁体   English

按下后立即弹出视图控制器

[英]Popping view controller immediately after pushing it

I want the view controller to check something, and if it's true it would allow the user to use the view controller, and if it's false it would show an alert to the user and send the user back where he/she came from. 我希望视图控制器进行检查,如果为true,则将允许用户使用视图控制器;如果为false,它将向用户显示警报,并将用户发送回他/她来自何处。

So I tried adding this to an if-statement at the end of viewDidLoad : 所以我尝试将其添加到viewDidLoad末尾的if语句中:

[self.navigationController popViewControllerAnimated:YES]

However, I got the error: 但是,我得到了错误:

2014-08-09 20:12:59.731 ProjectName[1978:60b] nested pop animation can result in corrupted navigation bar 2014-08-09 20:12:59.731 ProjectName [1978:60b]嵌套的流行动画可能会导致导航栏损坏

2014-08-09 20:13:00.118 ProjectName[1978:60b] Finishing up a navigation transition in an unexpected state. 2014-08-09 20:13:00.118 ProjectName [1978:60b]在意外状态下完成导航过渡。 Navigation Bar subview tree might get corrupted. 导航栏子视图树可能已损坏。

I learned from this StackOverflow question that calling pushViewController or popViewController before viewDidLoad finishes is unsafe. 我从这个StackOverflow问题中学到,在viewDidLoad完成之前调用pushViewControllerpopViewController是不安全的。 Are there any ways around this? 有什么办法解决吗?

TLDR: I'm trying to push a view controller onto the stack, show an alert, then pop the view controller off of the stack. TLDR:我正在尝试将视图控制器推入堆栈,显示警报,然后将视图控制器从堆栈中弹出。

EDIT: Added code. 编辑:添加代码。

This should be fairly easy provided you want to show the alert. 如果您想显示警报,这应该相当容易。

1 - Call [UIAlertView show] method from within viewDidAppear . 1-从viewDidAppear调用[UIAlertView show]方法。 It would be advisable to use viewDidAppear as it would be last in the view life cycle, when the view controller is fully pushed on the stack. 最好使用viewDidAppear因为在将视图控制器完全推入堆栈时,它将使用于视图生命周期中的最后一个。 So popping will be harmless. 因此,弹出将是无害的。

2 - In clickedButtonAtIndex delegate method, call popViewControllerAnimated . 2 -在clickedButtonAtIndex委托方法,调用popViewControllerAnimated

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM