iOS5 SplitViewController leaves BarButton visible while in landscape view on app startup - ios

I have a UISplitViewController with a UIViewController as master and a UINavigationController as my details controller (which contains an actual DetailsController as it's rootController).
In iOS5, at app startup (holding the device in landscape view), I add the splitViewController's view to my window but then I present a loginController on top of the splitViewController like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
KRMasterViewController *masterViewController = [[[KRMasterViewController alloc] initWithNibName:#"KRMasterViewController" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
KRDetailViewController *detailViewController = [[[KRDetailViewController alloc] initWithNibName:#"KRDetailViewController" bundle:nil] autorelease];
UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
[self.window addSubview:self.splitViewController.view];
LoginController *controller=[[LoginController alloc]
initWithNibName:#"LoginController" bundle:nil];
[self.splitViewController presentModalViewController:controller animated:false];
[self.window makeKeyAndVisible];
return YES;
}
As you can see the detailsController is my splitViewController's delegate. The problem is in iOS4, before the loginController gets displayed, the delegate method:
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem
forPopoverController:(UIPopoverController *)popoverController
is called then when I dismiss the loginController the delegate method:
- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
gets called. I guess iOS realizes really late that I'm in landscape but figures out before I got to the detailController so everything was cool. In iOS 5, the second method does not get called by the time I get to the splitViewController. This means I'm left with the barButtonItem visible in landscape view. Funny enough, if I rotate to portrait then back to landscape, the methods gets called properly from then on. Anyone ever experienced this before? Any solutions?

I've had similar problem. After app launch I present Login modalVC. But when I dismiss it, the BarButtonItem in detailViewController is still visible.
Just use
[self performSelector:#selector(presentLogin) withObject:nil afterDelay:0.1]
and it will magically start working.

I ended up switching the root controller from being a navigation controller (when logging in) to a splitview controller for the main menu:
-(void)goToLogin{
self.rootSplitController=nil;
UINavigationController* navController=[[UINavigationController alloc]init];
navController.navigationBarHidden = true;
self.rootNavController=navController;
[navController release];
LoginController *loginController=[[LoginController alloc]init];
[self.rootNavController pushViewController:loginController animated:false];
[loginController release];
[self.window addSubview:self.rootNavController.view];
}
-(void)goToMain{
self.rootNavController=nil;
MasterController *masterViewController = [[[MasterController alloc]
initWithNibName:#"MasterController" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc]
initWithRootViewController:masterViewController] autorelease];
masterNavigationController.navigationBarHidden=true;
DetailsController *detailViewController = [[[DetailsController alloc]
initWithNibName:#"DetailsController" bundle:nil] autorelease];
UINavigationController *detailNavigationController = [[[UINavigationController alloc]
initWithRootViewController:detailViewController] autorelease];
detailNavigationController.navigationBarHidden=true;
self.rootSplitController = [[[UISplitViewController alloc] init] autorelease];
self.rootSplitController.delegate = detailViewController;
self.rootSplitController.viewControllers = [NSArray arrayWithObjects:
masterNavigationController, detailNavigationController, nil];
[self.window addSubview:self.rootSplitController.view];
}

Related

How to deal with a presentModal inside a tabBar that needs to use navigationController

I'm trying to push a view controller inside a presentmodal but nothing happening. So, I have a loginController as rootViewController that push a tabBarControler then inside one of tabBar views I open a presentModal. In the presentModal I have an UITableView when clicked push another view but when I try do this nothing happen. To try be more clear here's the hierarchy:
LoginViewController(as root view controller) >>>push>>> UITabBarController(HomeViewController and two others) >>>open>>> PackViewController(presentModal) that needs to open another view by pushViewController:
The code:
AppDelegate.m
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
LoginViewController_iPhone *loginViewController = [[LoginViewController_iPhone alloc] init];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:loginViewController] autorelease];
self.window.rootViewController = self.navigationController;
LoginViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
HomeViewController_iPhone *referenciaHomeViewController = [[HomeViewController_iPhone alloc] init];
MapaViewController_iPhone *referenciaMapaViewController = [[MapaViewController_iPhone alloc] init];
GuiaViewController_iPhone *referenciaMidiaViewController = [[GuiaViewController_iPhone alloc] init];
UINavigationController *navHome = [[UINavigationController alloc] initWithRootViewController:referenciaHomeViewController];
UINavigationController *navMapa = [[UINavigationController alloc] initWithRootViewController:referenciaMapaViewController];
UINavigationController *navGuia = [[UINavigationController alloc] initWithRootViewController:referenciaMidiaViewController];
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:#"tabBarBackground"]];
[self.tabBarController.tabBar setSelectionIndicatorImage:[UIImage imageNamed:#"tabBarSelected"]];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navHome, navMapa, navGuia, nil];
}
- (void)login {
[self.navigationController pushViewController:self.tabBarController animated:YES];
}
PackViewController.m (PRESENTMODAL):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
CompraPackViewController_iPhone *controller = [[CompraPackViewController_iPhone alloc] init];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
When you do your present modal, you need to present a navigation controller whose root view controller is the table view controller.

xcode tabbed application with loginViewController

I am fairly new to xcode so apologies if I am asking bad questions. My issue is that I have created a tabbed application but would like a login screen to show before the tabs display. There a lots of posts about this and the consensus is that you need to get your tabBarController to present a view controller. This makes sense but for some reason my app is not displaying the login screen. I'm going to paste my appDelegate.m code below. Any help would be much appreciated.
Tks
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
sleep(3);
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
LoginViewController *loginViewController = [[[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil] autorelease];
UIViewController *viewController1 = [[[SecondViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = #[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[loginViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[_tabBarController presentViewController:loginViewController animated:YES completion:nil];
[self.window makeKeyAndVisible];
return YES;
}
You should do the presentation from the controller in the first tab (assuming that's the controller you want to show after the login screen is dismissed). Do the presentation from the viewDidAppear method with the animated argument set to NO.

How to Show LoginViewController over SplitViewController?

I am working on application for iPad which have CustomTabBar (3 Tabs), Navigation Bar and SplitView Controller.
Follow of application screens:
1-Login Screen (Present over SplitView) >> Forgot password (Push on login navigation)
2- Forget password if pushed on login navigation then it will be poped and then login will be dismissed on successful login.
3- On Successful Login, SplitView is shown.
How I code in AppDelegate:
self.detailViewController = [[[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil] autorelease];
UINavigationController *detailNavigationController = [[[UINavigationController alloc] initWithRootViewController:self.detailViewController] autorelease];
customTabBarCont = [[CustomTabBarController alloc] init];
self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.delegate = self.detailViewController;
NSArray *viewControllers = [[[NSArray alloc] initWithObjects:customTabBarCont,detailNavigationController, nil] autorelease];
self.splitViewController.viewControllers = viewControllers;
self.detailViewController.splitViewController = self.splitViewController;
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
loginVC = [[[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil] autorelease];
UINavigationController *loginNavigationController = [[[UINavigationController alloc] initWithRootViewController:loginVC] autorelease];
[self.splitViewController presentViewController:loginNavigationController animated:NO completion:nil];
I have SettingViewController in which i have given the functionality of Sign-out.
It create issues when user Signout from Portrait and Login in LandscapeView
How i code for SignOut
self.loginVC = [[[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil] autorelease];
if ([app_delegate.detailViewController.masterPopoverController isPopoverVisible]) {
[app_delegate.detailViewController.masterPopoverController dismissPopoverAnimated:NO];
}
UINavigationController *loginNavigationController = [[[UINavigationController alloc] initWithRootViewController:self.loginVC] autorelease];
When we rotate again then everything goes well. but how to solve this issue. or where i am wrong.
You just have to add one method in your DetailViewController.m
- (BOOL)splitViewController:(UISplitViewController*)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation {
return NO;
}
The run you project and see what happens. Surly this will solve your problem

iOS selected tab

I'm trying to determine which tab has been selected by the user. I melded this together from a couple of tutorials on iOS tab bars. In my appDelegate I have this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//We need to implement the view controllers within the tab controller and make the tab controller the root controller of our app - note we are only using view 1-3 at first.
FirstViewController *fistView = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
ThirdViewController *thirdView = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
FourthViewController *fourthView = [[FourthViewController alloc] initWithNibName:#"FourthViewController" bundle:nil];
NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:fistView, secondView, thirdView, fourthView, nil];
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewControllersArray animated:YES];
self.window.rootViewController = self.tabController;
//end custom code
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Is viewControllerArray the delegate for my tabController?
When I place this code on the page nothing happens:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if (tabBarController.selectedIndex == 0) {
NSLog(#"ok");
}
}
In this case, your app delegate should be the delegate for the tabBarController.
You can simply add self.tabController.delegate = self and make sure that your AppDelegate conforms to the UITabBarControllerDelegate protocol.
I also suggest placing a log outside the if in your delegate method, to confirm that it is actually called.

Issue Presenting View modally after a UISplitView loads

I'm new to UISplitView development, so I'm sure there is something obvious I'm doing wrong. I have a basic UISplitView iPad app that loads up with two UITableView controllers when the app launches. This works just fine.
What I am trying to do is immediately upon launch, presenting an "authentication" view modally so that a user will need to login before continuing. Here is the code I have so far which compiles and works without breaking, but the view is not showing.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
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];
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
masterViewController.detailViewController = detailViewController;
masterViewController.managedObjectContext = self.managedObjectContext;
self.window.rootViewController = self.splitViewController;
[self presentAuthenticate];
[self.window makeKeyAndVisible];
applicationDidLaunch = YES;
return applicationDidLaunch;
}
- (void) presentAuthenticate {
AuthenticateViewController *loginController = [[AuthenticateViewController alloc] initWithNibName:#"AuthenticateViewController" bundle:nil];
[loginController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[loginController setModalPresentationStyle:UIModalPresentationFormSheet];
if ([self.splitViewController respondsToSelector:#selector(presentViewController:animated:completion:)]) {
[self.splitViewController presentViewController:loginController animated:NO completion:nil];
} else {
[self.splitViewController presentModalViewController:loginController animated:NO]; //iOS 4 works fine with or without animation
}
}
I defined the AuthenticateViewController as a View with a few textfields in it and have it wired to the File's Owners view.
Thanks ahead of time!
A viewcontroller will not allow to push/present on anotherview unless and until the view is complete loading.
Simple saying we are not allow to call presentModalViewController/pushViewController in a viewcontroller viewDidLoad/viewWillAppear. we need to call this in viewDidAppear.
I had the same issue you said.
Some Solution I can say are,
Do the loading of AuthenticateViewController after [self.window makeKeyAndVisible]; and in a performSelctor (may be with a delay).
Move the code to display AuthenticateViewController in SplitView's DetailView controller viewDidAppear.
thanks,
Naveen Shan

Resources