With the following code:
MyModalViewController *mMVC = [[MyModalViewController alloc] init];
UINavigationController *mMNavVC = [[UINavigationController alloc] initWithRootViewController:mMNavVC];
mMNavVC.navigationBar.barStyle = UIBarStyleBlackOpaque;
[[[appdelegate window] rootViewController] presentViewController:mMNavVC animated:YES completion:nil];
[mMVC release];
[mMNavVC release];
//(Yes we are not using ARC yet - kills me)
the view presents but it does not load before fully sliding up to the top. The Nav controller does load properly and you see it slide all the way up. However it's just a frame. In other words, you can see the presenting view controller as the nav controller slides up into place - THEN the mMVC loads.
Thanks for the help!
Your problem is that you are trying to create a UINavigationController while using it as the UINavigationController rootviewcontroller. Fixing this line :
UINavigationController *mMNavVC = [[UINavigationController alloc]
initWithRootViewController:mMNavVC];
to this :
MyModalViewController *mMVC = [[MyModalViewController alloc] init];
UINavigationController *mMNavVC = [[UINavigationController alloc] initWithRootViewController:mMVC];
will load the modal view controller before showing it.
MyModalViewController *mMVC = [[MyModalViewController alloc] init];
UINavigationController *mMNavVC = [[UINavigationController alloc] initWithRootViewController:mMNavVC];
mMNavVC.navigationBar.barStyle = UIBarStyleBlackOpaque;
[[[app window] rootViewController].navigationController pushViewController: mMNavVC animated:YES];
[mMVC release];
[mMNavVC release];
Try adding a line where you access that vc's view, i.e.
MyModalViewController *mMVC = [[MyModalViewController alloc] init];
UINavigationController *mMNavVC = [[UINavigationController alloc] initWithRootViewController:mMNavVC];
mMNavVC.navigationBar.barStyle = UIBarStyleBlackOpaque;
mMVC.view.backgroundColor = [UIColor whiteColor];
[[[appdelegate window] rootViewController] presentViewController:mMNavVC animated:YES completion:nil];
[mMVC release];
[mMNavVC release];
This is kind of a workaround for a problem that your viewController's view doesn't get loaded before navigationController's viewDidAppear method is called. If what I posted doesn't work, the problem is elsewhere.
Just try it and tell if it's ok now. :)
OK. Everybody gets a 1up for their answers because they were all helpful to me.
LucOlivierDB gets the check mark because that was just a stupid thing for me to not have seen.
!!NOTE:!! As it turns out my real problem as this line of code:
self.view.backgroundColor = [UIColor clearColor];
Someone thought it would be clever to have all the views inherit the background by making the view transparent. So when it drew the view it was drawing it transparent. Since the was not considered done drawing until the modal action was done you could see the view beneath it before that.
Thanks guys. You call made me think and learn!
Related
After searching a lot for a solution to my problem and didn't found a correct answer I post the problem: I have two viewControllers company and companyDetail when I execute
CompanyViewDetail *cDetail = [[CompanyViewDetail alloc] init];
[self presentViewController:cDetail animated:YES completion:nil];
it navigate to companyDetailViewController but the tabBar that I created in AppDelegate disappear, here is the code:
tabBars = [[UITabBarController alloc] init];
self.window.rootViewController = tabBars;
self.tabBars.view.autoresizingMask = (UIViewAutoresizingFlexibleHeight);
[self.window makeKeyAndVisible];
I'm trying to show a popover with a title, creating a root view controller and instantiating it with my viewController. But, when I show the popover, the content is not shown. Here is the code:
UIViewController *popContentViewController = [[sb instantiateViewControllerWithIdentifier:#"videosTutoriais"] init];
UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:popContentViewController];
_popover = [[UIPopoverController alloc] initWithContentViewController:controller];
_popover.delegate = self;
[popContentViewController release];
[controller release];
//dados.myPopoverController = popOverController;
[[self popover] presentPopoverFromRect:ancora.bounds inView:ancora permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Just to be more specific, the title of popover appears normally, but the content doesn't.
Just double check that popContentViewController is not nil. You have the identifier #"videosTutoriais" which looks like it might be a scanning error.
From your code, you are releasing the controller before you display in on the screen. Try releasing it after or in the dealloc method. If you are unsure about memory management. I suggest you try ARC instead to avoid silly errors and mistakes such as this.
The code looked like this:
sb = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad" bundle:nil];
UINavigationController *controller = [[sb instantiateViewControllerWithIdentifier:#"navTutorial"] init];
_popover = [[UIPopoverController alloc] initWithContentViewController:controller];
[[self popover] presentPopoverFromRect:ancora.bounds inView:ancora permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[controller release];
I'm trying to convert my app to universal for iPad support and whatever I do I can't get rid of the "Splitview controller is expected to have a view controller at index 0 before it's used!" error right after the app stars.
I'm using iOS6 as target, XCode 4.6.3. Tried all the things that I could find on this website and Google, didn't help me at all.
I want to add a TabBar controller as a Main one (left one in the Split Controller) and some other controllers as a detail one.
Here is my current code in AppDelegate.m:
tabController = [[UITabBarController alloc] init];
[tabController setViewControllers:[NSArray arrayWithObjects:navAddVC, nav, svcNav, stvcNav, nil]];
FirstDetailViewController *fdvc = [[FirstDetailViewController alloc];
initWithNibName:#"FirstDetailViewController" bundle:nil];
UINavigationController *fdvcNav = [[UINavigationController alloc] initWithRootViewController:fdvc];
viewControllers = [[NSArray alloc] initWithObjects:tabController, fdvcNav, nil];
UISplitViewController *splitvc = [[UISplitViewController alloc] initWithNibName:nil bundle:nil];
[[splitvc view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"splitViewControllerBG"]]];
[splitvc setViewControllers:viewControllers];
[splitvc setDelegate:fdvc];
[[self window] setRootViewController:splitvc];
[[self window] makeKeyAndVisible];
I'd appreciate any help, thanks.
Thanks to #Wain I solved it.
The thing was that by setting up a background image to my split vc I was loading its view.
So the solution is to set viewControllers array before the setting background color.
In my delegate class I have this -
BluenibViewController *mvc = [[BluenibViewController alloc] init];
UINavigationController *unvc = [[UINavigationController alloc] init];
[unvc pushViewController:mvc animated:NO];
[mvc release];
[self.window addSubview:unvc.view];
[self.window makeKeyAndVisible];
return YES;
and in my BluenibViewController I have this method -
-(IBAction) BookingsViewController:(id)sender
{
bookingsViewController1 = [[BookingsViewController alloc]
initWithNibName:#"BookingsViewController"
bundle:nil];
UINavigationController *navController = self.navigationController;
[navController pushViewController:bookingsViewController1 animated:YES];
self.title = #"Bookings";
[self.window makeKeyAndVisible];
[self.view addSubview:bookingsViewController1.view];
[navController release];
[bookingsViewController1 release];
}
Ob click of this method I am able to go to the next view but there is no back button on the navigation bar.
Please point me to the silly mistake I am doing.
I see quite a few errors here. Lets see if I can't be of some service.
First, I see that you're overreleasing your navigation controller [navController release];
Second, you should only have to make the window key/visible once in your entire project. You set your navController as the rootViewController for your window, make it key/visible, and then you should never have to do anything with your window again. Don't think it's breaking anything, but you should remove all calls to make key/visible beyond the first.
In the end, pushing a new view controller should look like this:
[self.navigationController pushViewController:[[[BookingsViewController alloc] init] autorelease] animated:YES];
You shouldn't need anything else to get what you're looking for.
You should not add unvc.view as a subview of self.window. You should just assign unvc as self.window.rootViewController:
self.window.rootViewController = unvc;
and you should not add bookingsViewController1.view as a subview of self.view (in your BookingsViewController: method). The navigation controller will take care of getting bookingsViewController1.view onto the screen after you have pushed it.
self.navigationItem.hidesBackButton =YES;
Follow this code . Hope it helps ....
it comes a little bit late but in iOS 8 you can do:
[self.navigationController pushViewController:secondViewController animated:YES];
i was searching this whole afternoon in hope of solution but i didn't manage to find anything helping me solve the problem.
The problem is, i have no intention of using UINavigationController until a button gets taped, and after that i would like to present view controller containing a navigationcontroller, or reverse, modally. in my search i came across this solution:
MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:#"MyExample" bundle:nil] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
[self presentModalViewController:navController animated:YES];
which i then used it in my code and found out it is not working, to make sure i started a practice project from viewbased project templet and added this to the first view controller
- (IBAction) buttonGotPreseed{
testino *testController = [[testino alloc] initWithNibName:#"testino" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:testController];
testController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:testController animated:YES];
[nav release];
[testController release];
}
didn't work also, im not seeing the navigation bar up there
any help would be greatly appreciated
You're pushing the root view controller, not the navigation controller itself. Line 5 should be:
[self presentModalViewController:nav animated:YES];