I am making an application that has a UITabBar and it works just fine, however I want to add a first screen which contains some instructions and a logo, then a button and when said button is pressed to show the UITabBar I've tried for a couple of days to do this on my own with no luck, I'm not even sure if it can be done, could anyone help me out? or give me a lead?
Try setting up the tab bar application, and then showing the first screen over it as a modalViewController. Inside your main app's viewController:
FirstViewController *firstViewController = [FirstViewController alloc] initWithNibName:#"FirstView" bundle:nil];
[self presentModalViewController:firstViewController animated:NO];
[firstViewController release];
When the button is pressed inside the modal view, call:
[[self parentViewController] dismissModalViewControllerAnimated:YES];
to get rid of it. You can adjust the animation style for the dismissal, or use NO instead to have it just disappear.
Related
I'm a bit lost trying to figure it out...
I have a tab bar based app with login screen at the start. Login screen should be done as Modal View Controller BEFORE tab bar controller appears.
The problem is that I can present it only in viewDidAppear: method of TabBarController. And user can see for half a second content of the UITabBarController. I've tried to move call to viewDidLoad: or viewWillAppear: but it logs an error in console: "whose view is not in the window hierarchy!". As far as I can understand you can only add ModalViewController when all child UIViewControllers of UITabBarController are loaded, ad that happens in viewDidAppear: delegate method.
Do you have any solution how to show login screen without showing TabBarController before?
I've tried 2 ways of displaying ModalViewController, both of them work in viewDidAppear: only
XIB file with login view and using presentViewController: code
self.loginController = [[LoginViewController alloc] init];
[self presentViewController:self.loginController animated:NO completion:nil];
Storyboard, modal segue and calling it from the code:
[self performSegueWithIdentifier:#"loginScreen" sender:self];
Instead of a modal, you might consider pushing the login screen onto a navigation stack. Inside viewWillAppear: you can just instantiate your login viewController and push it. You could also do it in viewDidLoad if you'd like.
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController pushViewController:yourInstantiatedLoginViewController animated:NO];
}
I got the popup, used at 2 locations within my app, one time in a navigation controller one time without navigation controller,
i got one button in a uitoolbar (select button) but this button has it's own life for some reason
The one in the navigation controller is working perfectly.
But the one called without navigation controller resizes this popup so i resized it back in the code like
- (void)showModal:(UIViewController *)controller
{
[controller setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentViewController:controller animated:NO completion:nil]; //Method used without navigationcontroller
[controller.view setBounds:CGRectMake(0,0, 600, 748)]; //resize => button doesn't work at all
//[controller.view setFrame:CGRectMake(0, 0, 600, 748)]; //resize => button only registers click event left from the actual button
//[[NSNotificationCenter defaultCenter] postNotificationName:#"show modal" object:controller]; // Method used within navigationcontroller
}
I've been looking all over google but i can't find anything on this problem.
Hope I have more luck here.
Probably the easy way to sort this problem out is to put it in a UINavigationController and use that to pop up. Then you don't have to use a UIToolBar.
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewControllerToPopUp];
[viewController setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentModalViewController:navController animated:YES];
This way the viewController you are presenting stays simple and you already know the button works when it is a navigation controller :)
I'm trying to achieve something similar to user of this post:
Xcode/iOS: How to hide Navigation- AND ToolBar on scroll down?
I'm able to hide (or unhide using NO) the navigation bar successfully using the code:
[[self navigationController] setNavigationBarHidden:YES animated:YES];
However, when I attempt to hide the toolbar using the code:
[[self navigationController] setToolbarHidden:YES animated:YES];
Nothing happens. I then noticed when unhiding the toolbar that I received an additional blue toolbar that I didn't realize existed. This screenshot shows this:
Screenshot
I do not want the blue bar. What I am trying to do is hide or unhide the Black toolbar with the icons on it. (the UITabBar).
I think what I need to do is somehow I need to access the navigation controller of one of the parent view controllers and call the setToolbarHidden on the navigation controller of that view. However, I can't seem to figure out how to do this.
I've tried the following and all seem to have no effect:
[[[self parentViewController] navigationController] setToolbarHidden:YES animated:YES];
or
[[[[[[UIApplication sharedApplication] delegate] window] rootViewController] navigationController] setToolbarHidden:YES animated:YES];
My view controller storyboard consists of the following:
The InitialViewController is a TabBarViewController. It contains three children. One of those children is a UINavigationController. This navigation controller gets several UITableViewController pushed onto it, and eventually a UIViewController is pushed. This last UIViewController is what is seen in the screenshot.
Rough Layout:
TabBarViewController
UIViewController
UITableViewController
UINavigationController
UITableViewController
UITableViewController
UITableViewController
UIViewController
I've tried using
[self parentViewController] parentViewController] parentViewController] ...
to attempt to get back to the top, but this hasn't seemed to work either.
Any suggestions?
I think the problem here might be related to UITabBarController not having a UIToolbar. The setToolbarHidden: method will only apply to the UINavigationController's built-in toolbar (see Apple's documentation). If it's the UITabBarController's tab bar that you actually want to hide, take a look at this post which links to a method using UIView animations directly on the UITabBar.
I have a ViewController which I'm using a modal transition for. It has a toolbar and I've added five items (including space) in interface builder. I'm trying to set the buttons from code, so when the table view in this modal ViewController is being edited, show a 'lock' button, when it's not editing, show an 'unlock' button.
Despite my attempts, the buttons aren't changing.
I've tried (updated 13th Jan):
[self setToolbarItems:...animated:true]; // failed
[self.navigationItem setLeftBarButtonItems:... animated:true]; // also failed, though self.navigationItem is not null
[self.parentViewController setToolbarItems:... animated:true];
[self.navigationController setToolbarItems:... animated:true];
[self.tabBarController setToolbarItems:... animated:true];
[self.navigationItem setLeftBarButtonItems:... animated:true];
[self.navigationController.toolbar setItems:
All of which failed.
This ViewController is shown from another VC (non modal), which is pushed onto a NavigationController.
Am I going about this wrong?
Rather than changing the buttons in the toolbar, I eventually just added a button in Interface Builder and changed the background image:
btnLock.image = [UIImage imageNamed:#"lock_open_white_30.png"];
If you really did need to change the buttons, you'd probably need to create all the buttons and expose them on your ViewController, the use setHidden to hide/show them.
I have problem when using modalPresentationStyle.
I call the following function in my tabbarcontroller's first view controller's viewDidload
So that the login viewController is displayed when app launches
But the problem is when I launch app in Landscape mode I can see the login view correctly and I rotate the iPad to portrait mode the background of login viewcontroller that is my First tabbar viewcontroller goes up by about 20pixels
I create a new app to check and I found this will only happend when we use tabbar.
and when App launches in portrait mode its works great!
-(void)gotoCredentials {
Login *objLoginViewController=[[Login alloc] initWithNibName:#"Login" bundle:nil];
UINavigationController *objnavigationController = [[UINavigationController alloc]
initWithRootViewController:objLoginViewController];
objnavigationController.modalPresentationStyle=UIModalPresentationFormSheet;
objLoginViewController.modalPresentationStyle=UIModalPresentationFormSheet;
[self presentModalViewController:objnavigationController animated:YES];
//[self.tabBarController presentModalViewController:objnavigationController animated:YES];
[objLoginViewController release];
objLoginViewController=nil;
[objnavigationController release];
objnavigationController=nil;
}
thanks in advance!
sorry it is fixed by setting tabbar controller selection
[m_objTabBarController setSelectedIndex:0];
after creating tabbar. I dont know that happens here.
But I think to do so is because after dissmiss FormSheet and change the tab then looks fine so I try setting tabbar selected index and it work great...