NavigationController and View Hierarchy issue - uinavigationcontroller

I have 1 (rootViewController) view controller which is embedded in navigation controller. Then i pushed another view controller (secondViewController), which has search controller in title view. When i am trying search become first responder (Active) i got this in terminal:
Warning: Attempt to present
"AppName.CustomSearchViewController: 0x7face0c20eb0> on
whose view is
not in the window hierarchy!
This happens only in iOS lower than 11. When i embed this second view controller in navigation controller and present it modally all works good, but i need exactly pushing. How can i solve this?

I solved it! I need to make definesPresentationContext false in rootViewController to make it work on another one!

Related

How to unwind from UINavigationController to UIViewController?

I'm trying to use an unwind segue from a UINavigationController subclass to a UIViewController subclass. My issues arise arise (I believe) because my navigation controller is the root view controller of my UIWindow. I attempted to set my UIViewController as the root and then modally present the navigation controller before my AppDelegate finishes launching, but that doesn't work because the view is not added to the hierarchy.
Any ideas?
EDIT:
Is there anyway to attach a segue to the top view controller of the navigation controller? I have a fairly large storyboard and would like to avoid repeating myself on multiple controllers.
I'm currently struggling with using unwind segue past navigation controller myself too but maybe that article I found can help you. It describes (with GitHub project attached) how to use unwind segues whilst under the aegis of a UINavigationController:
https://github.com/simonmaddox/CustomUnwindSegue/tree/master
PS - Regarding your Edit: If you can get it to work following SimonMaddox steps in the link I suggested, the method should then work from any ViewController under the Navigation Controller I think.

Combining a navigationcontroller and a root view controller with pages

I have a problem that has been solved on iOS6, but still appears if I use the iOS 5.1 simulator.
I have a default page based application. I added a "Main menu" view controller, that has three buttons that activate the root view controller containing the pages via a push segue, all defined in the storyboard.
I then added a navigation controller and made it the initial view controller.
If I pas the menu via a button and flip a few pages I can click the back button and it goes back to the menu. Good.
But I don't want the nav bar, so I hide it, and on the root view controller that contains the page view controllers I add a button which performs this action:
[self.navigationController popToRootViewControllerAnimated:YES];
This button works perfect on iOS6, I can flip a few pages, press the button and I'm back in the menu.
With the iOS 5.1 simulator however (and on my 5.1 iPad), a page flip occurs! It's a page filp until I'm on the last page and then I go back to the menu.
I searched for over two hours now but could not find a solution, I hope someone can help me with this?
Note: setting animated to NO does not solve the problem.
I did find the answer to my question, this is my first iOS project which explains why I did not find it any sooner myself.
In the default page based application there are two lines in the viewDidLoad method:
// Add the page view controller's gesture recognizers to the book view controller's view so that the gestures are started more easily
self.view.gestureRecognizers = self.pageViewController.gestureRecognizers;
First, it's not really adding but assigning that happens here, second, when I put the second line in comment, everything works as expected.
So I'm glad it solves my problem, however it raises some questions:
The gestures are started as easy as they were, so why was this line needed in the first place, what does it supposedly fix?
Why does it work in iOS6? It should have had the same problem, no?
Is it correct that it is an assignment and not an addition?
Any answers to these three are still appreciated.
Alex

I can't change initial Xcode storyboard view

I'm trying to change my initial view in my storyboard, but, when I change it I get this strange view:
Anyone can tell me why?
Ps: In my project I don't have any tab controllers, so I don't know why there is a tab over there...
Is it possible you are doing a universal app and are looking at the wrong View?
What you have there is a navigation bar in a blank view and probably a message in your messages telling you that you have not got a root view controller.
In the past I have solved this by
a) Restarting XCode.
b) Making a new view, copying and pasting the essential View Controller from my old View and deleting the old View.
c) Checking in my summary that the view I think is being talked to actually is the one specified.
d) Looking at my storyboard and checking that the viewcontroller is specified in the object inspector as "Is initial View Controller" by checking the box.

UIBarButtonItems not showing up on UIToolbar

I have a UINavigationController with toolbarHidden set to NO.
I have added UIBarButtonItems to navigationController.toolbar.
The toolbar is displayed, but the buttons are not...
What gives?
Ok so apparently I misunderstood the usage of the setItems method on navigationController.
To remedy this I set the toolbar items on each view controller that is pushed onto the navigation controller's stack.
I guess if I wanted to have one toolbar persist through all the views I could add a new toolbar to the view controller holding my navigation controller then simply invoke setItems on my navigation controller.
I digress.

Autorotate with a UINavigationController

I am a little unclear on how to rotate views that are sitting on a UINavigationController.
I have overridden the UINavigationController object with one of my own that overrides:
(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { return YES; }
I have one view on the stack on the controller and that view is loaded from a xib with two views in it. I want to switch from portrait to landscape. Normally I would handle this by changing the view from within the nib files of the view itself. Do I have to implement the rotational code within the Navigation Controller or just within my view code?
(void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
That willAnimate code is what I'm used to using in the view itself, but I'm still not seeing the view being changed, and I'm thinking it may be that I need to access the view in the NavigationController and change that, or even override the same method in the Navigation Controller and do my view switching there.
Any suggestions? I've never actually done this before and just found out the TabViewControllers and NavigationControllers are both portrait mode only by default.
Turns out it wasn't possible to change the view because I was trying to changes the RootView on the Navigation Controller. I got around this by placing my own pseudo root view controller that never gets seen in the root spot on the Navigation stack. I overrode a few of the navigation controls to account for this so the functionality would continue the same and I'd be able to change my desired perceived root view as I needed to.
A start in the right direction can be found in this link:
http://starterstep.wordpress.com/2009/03/05/changing-a-uinavigationcontroller’s-root-view-controller/

Resources