Is it possible to check inside ViewController class that it is presented as modal view controller?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- 关于Asp.net Mvc Core重写Initialize方法的问题
- Spring: controller inheritance using @Controller a
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Unable to process app at this time due to a genera
Since
modalViewController
has been deprecated in iOS 6, here's a version that works for iOS 5+ and that compiles without warnings.Objective-C:
Swift:
Hat tip to Felipe's answer.
Best way to check
In my project I have a view controller (Detail) that can be presented either modally (when adding a new item) or with push (when editing an existing one) by Master view controller. When user taps [Done] the Detail view controller calls Master view controller's method to notify that it is ready to be closed. Master has to determine how Detail is presented in order to know how to close it. This is how I do this:
Petronella's answer does not work if self.navigationController is modally presented but self is not equal to self.navigationController.viewControllers[0], in that case self is pushed.
Here is how you could fix the problem.
And in Swift:
Here's my modified version of @GabrielePetronella's
isModal
, which works with contained view controllers in that it walks up the parentViewController hierarchy first. Also pulled the code out into multiple lines so it's clear what it's doing.A hack like this might work.
However, I think my previous answer is a cleaner solution.