I launch a modal view controller and in its init I have the following code:
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
viewController = [[UIViewController alloc]init];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
I need the viewController for entering some data in it. How can I release the window and viewController so that I can go back to the viewController that launched the modal view controller? At this point, after I'm done doing what I need in the modal view, I am trying:
[viewController.view removeFromSuperview];
[window removeFromSuperview];
but just end up with the modal view's parent (the one that lanched the modal view) just frozen(it's not really frozen, it is just not user interactible because there are the window and view controller in front of it and the view controller doesn't have size and background
iOS app should only contain one UIWindow.
And you can easily present UIViewController with in viewController
[self presentModalViewController:navigationController animated:animated];
Then just call in that viewController to dismiss it:
[self dismissModalViewControllerAnimated:YES];
Related
I am pushing a controller via:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
Once there, I cannot go back with either
[self dismissViewControllerAnimated:YES completion:nil];
or
[self.navigationController popViewControllerAnimated:YES];
what should I use to dismiss the last view ?
To where you want to dismiss and go to?
This is the root view controller right? It cannot be "dismissed".
If you have a another view controller and this VC is pushed or modally presented from the second VC it can be dismissed
Window is the base canvas and VC's are added over it and shown.
Ok from your clarification you have an initial VC with contacts and you are trying to go to next page(DetailsVC) from that contactVC and then dismiss back from there.
What you currently doing is getting the window and making your detailVC as the root VC.This way you cannot dismiss to the contacts VC.Make an instance of the detail VC in the didselectRowAtIndexpath method of contactsVC and push it using navigation controller.
Then you can pop using the method popViewControllerAnimated:
This is an excellent tutorial for you to start on
Your code is not "pushing a controller". That code is essentially what you may find in your app delegate for setting up your one initial window and view.
Calling popViewController only works after you've pushed a controller onto that same navigation controller using pushViewController, which you haven't done.
Calling dismissViewController only works after you've presented a view controller with presentViewController, which again you haven't done.
I finally left the above technique and went for the traditional:
ViewController *detailViewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
i have a tabBarController application and using .xib files for the interface not the storyboard
i have this code by default in the appdelegate
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[PopAdsFirstViewController alloc] initWithNibName:#"PopAdsFirstViewController" bundle:nil];
UIViewController *viewController2 = [[PopAdsSecondViewController alloc] initWithNibName:#"PopAdsSecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
i have created a Login View and don't know how to show it before the tabBarView and hide t after a successful login.
One way would be to show it as a modalView on launch. Dismissing upon successfull login?
eg:
UIViewController myLoginViewController = [[MyLoginViewController alloc] init withNibNamed:"MyLoginViewController"]; //Or whatever you instantiation is
[myTabViewController presentModalViewController:myLoginViewController animated:YES];
And to dismiss it (Hide it)
//This should be done from the original View Controller i.e. myTabViewController preferably in a delegate called by the modal view controller.
[self dismissModalViewControllerAnimated:YES];
Documentation on modalViewControllers:
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html
The way that I did it for one of my apps is to just add them in the correct order. Add your tabbar controller to your window, then add the login controller over the top of the tab bar. Then show your window. The user won't see anything but your login controller. Once you login, you can just remove the login controller from view.
This way is probably best if you have information you need to hide until login. The other way is to only launch the login view only. On successful login, remove the login and add the tab bar controller. Either way is fine.
Presenting modally is probably the easiest, but requires a view in place before presenting. So if the data and view under the login controller isn't that sensitive, you could consider this option.
Another way would be using LoginViewControllerDelegate in your appDelegate.h file
In your .h
#import "yourLoginViewController"
//and add LoginViewControllerDelegate
Then in your .m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
yourLoginViewController *loginView = [[yourLoginViewController alloc] initWithNibName:#"yourLoginViewController" bundle:nil];
loginView.delegate = self;
[window addSubview:loginView.view];
[window makeKeyAndVisible];
}
//add this one
- (void)loginViewControllerDidFinish:(yourLoginViewController *)loginViewController {
[window addSubview:tabBarController.view];
}
I am creating an application which I want to have a view controller with buttons as the first view controller with no navigation bar, and then when the user selects a button a table view controller appears managed by a navigation controller.
At the moment I am setting up the navigation controller in the app delegate and setting the top view controller as the table view controller I want to start the navigation bar on. So far I can see the navigation bar but that is it when I transition from the first view controller to the table view controller.
Any help would be much appreciated as I have confused myself with this issue.
I'm not totally clear on what you are asking, so I might have it wrong, but here goes.
The top navigation bar is can be displayed or hidden by calling:
self.navigationController.navigationBarHidden = NO;
In the viewWillAppear method of your viewController. So set it to YES or NO depending on whether or not you want it to be displayed.
#Disco, you would do something like so:
// In the App delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CustomViewController *viewController = [[CustomViewController alloc] init];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
// In your button method
- (IBAction)loadUpTableViewController:(id)sender {
CustomTableViewController *tvc = [[CustomTableViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tvc];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[tvc release];
}
my first xib contains a ScrollView with a springboard like interface in MainWindow.xib:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
navController = [[UINavigationController alloc] init];
[navController setNavigationBarHidden:YES];
[window addSubview:navController.view];
[window sendSubviewToBack:navController.view]; }
When a button is clicked the FirstViewController appears with a tableview and a navigation controller:
- (void) buttonPushed:(id)sender {
FirstViewController *firstViewController = [[FirstViewController alloc] init];
[navController pushViewController:firstViewController animated:YES];
[firstViewController release];
[window addSubview:navController.view]; }
When I click the back button in Navigation Controller to go back to springboard, I get the springboard xib, but unresponsive to touches with a Navigation Bar on top!
- (void)goHome:(id) sender {
[self.view removeFromSuperview];
How can I go back to springboard screen (mainwindow.xib) without having the navigation bar stacked on top, and be responsive to touches ?
Why don't you set the springboard view to be the root view controller of your navigation controller and get rid of any UI in the window?
I think that the window shouldn't have any UI elements accept view of view controllers that are added to it (by navigation controller or by tab bar controller).
This way you won't have to reinvent the wheel for the first view to load from the springboard view and the back button will work properly.
You can set the navigationBarHidden property to false in the viewDidLoad method of the root view controller (the view controller of the springboard view).
Did you try calling [navController setNavigationBarHidden:YES]; in your mainview viewWillAppear callback ?
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
UIViewController *rootController = [[MyRootViewController alloc] init];
navigationController = [[UINavigationController alloc]
initWithRootViewController:rootController];
[rootController release];
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
}
Ever since I've taken one of my UIViewController subclasses and present it to the user in the form of a modal view, with presentModalViewController:animated.. I haven't been able to dismiss it using:
[self dismissModalViewControllerAnimated:YES];
I do believe this is some odd mixup with how I'm instantiating a UINavigationController on the modalViewController, with code that looks like the following (similar code is also in the App Delegate):
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
navigationController =
[[UINavigationController alloc] initWithRootViewController:self];
navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
The navigation stack works as expected, but unless I remove it, I can't dismiss the modal view controller any longer. I'm under the impression that I shouldn't be adding a subView to UIWindow more than once and that's just one of the problems.
Make sure you call dismissModalViewControllerAnimated on the parent of the modal view controller, not on the modal view controller itself.