I wrote my code like this
- (void)menuButtonClick:(id)sender{
ViewController *test = [[ViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:test];
[self presentViewController:navController animated:YES completion:nil];
}
But I discover that the view goes transparent when moving into the screen. The view turns to white as it should be after the animation.
like this.
If the GIF is not playing, please open it in a new tab.
Could you please tell me how to solve this problem?
Related
I wanted to Push New View Controller with Transparent Background on top of one View Controller which is already shown. I know How to PRESENT but I wanted to PUSH new View Controller.
UIViewController *controller = [[UIViewController alloc] init];
self.definesPresentationContext = YES;
controller.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:controller animated:YES completion:^{}];
You need to give memory to your ViewController and set to RootController of UINavigationController. After that, you can push it from your current controller...
UIViewController *yourViewController = [[UIViewController alloc] init];
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:yourViewController];
[self presentViewController:navigationController1 animated:YES completion:nil];
i'm trying to implement a modal presentation of my settingsViewController. This works fine, but when it is presented it is not showing the tableView which is in the SettingsViewController. It just show a grey background and navigation bar. How come it is not showing my tableView inside the SettingsViewController?
SettingsViewController *settingController = [[SettingsViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:settingController];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navigationController animated:YES completion:NULL];
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!
I'm just trying a really simple example here as I start to delve into iOS development for ipad.
I'm creating a split view and immediately trying to present a modal form sheet.
Should be really basic.
With what I've tried I get what behaves like a page sheet instead.
In landscape I can see the split view beneath but I don't see the top of my modal view (the tool bar is hidden but is in view in portrait).
I would expect to just grey out the split view beneath a 540x620 modal dialog. I should see the split view beneath my modal in both portrait and landscape like all the nice form sheet dialogs in the Cheddar app for example.
I must be doing something wrong here but all the examples I've read and same within the Cheddar app are doing pretty much what I outline below.
In the app delegate:
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = #[masterNavigationController, detailNavigationController];
self.window.rootViewController = self.splitViewController;
[self.window addSubview:self.splitViewController.view];
ModalViewController *modalView = [[ModalViewController alloc] initWithNibName:#"ModalViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:modalView];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self.splitViewController presentViewController:navController animated:NO completion:nil];
The app delegate is way too soon. You have no interface yet, so you can't coherently do any presenting of any view controller.
So, first thing, move all your modalView code to the viewDidAppear: of your detailViewController.
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];