Modal view after start app does not appear - objective-c

Before the users can use my app the have to login. My idea was that after the app starts the login view appears modally.
Before iOS 5 I had it all working with .xib files. Now I want to convert the views to a Storyboard for overview and better use of the new functionalities.
The app works with a splitview controller. The problem is that the login view is loaded, but never appears.
I tried it in the app delegate and I made a class for the splitviewcontroller and tried to load it in the viewDidLoad.
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
//load and push login
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
LoginViewController *loginViewController = [storyboard instantiateViewControllerWithIdentifier:#"loginViewController"];
NSLog(#"login push: %#", loginViewController);
[self presentModalViewController:loginViewController animated:YES];
NSLog(#"done push");
}
Log:
2012-01-13 10:18:08.217 App[1101:707] login push: <LoginViewController: 0x472fe0>
2012-01-13 10:18:08.330 App[1101:707] done push
I tried to load it in the Root or detail view, it works but its not the right place and xcode gives the message:
2012-01-13 10:18:08.807 App[1101:707] Unbalanced calls to begin/end appearance transitions for <MainSplitViewController: 0x464bc0>.
My first idea is to begin with the login view and after login push the splitview controller. But I found out that the splitview controller has to be the root view.

To push another ViewController in viewDidLoad is very early. Maybe the current ViewController is presented with animation and you try to present another ViewController with animation ...
You should try moving the display of your LoginController to viewDidAppear ...

Related

Set SplitView Controller as root controller after Login IOS

Hi I am new to IOS development and developing IOS application in which I am using split view controller. My split view controller is not at root position.I am doing login first and then open split view controller. So what I did after user login successful I am changing root view controller. Here is what I did till now:
On sign in button click I am changing root view controller as split view controller like this
- (IBAction)signinAction:(id)sender
{
NSLog(#"inside sign in .... ");
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
delegate.window.rootViewController = [[UserProfileController alloc] init];
[self dismissViewControllerAnimated:YES completion:nil];
}
User profile is my detail view controller for my split view.
#interface UserProfileController : UIViewController<UISplitViewControllerDelegate>
#end
but after click sign in button it opens black window. Don't know whats going wrong. Am I doing some thing wrong? Need Help thank you.
first thing you should change id of your UISplitViewController to Split
after just don't make any connection between your first controller and the split view controller. Then in code switch to it with this code:
- (IBAction)signinAction:(id)sender
{
UISplitViewController *split = [self.storyboard instantiateViewControllerWithIdentifier:#"Split"];
self.view.window.rootViewController = split;
}

How to presentModalViewController without dismiss the TabBarController

Hey guys i`m trying to present a modal view controller inside an application with a tab bar controller. The problem is, every time the new view is presented, it on top of my tab bar.
I need to keep my tab bar even when the view is presented. Like google maps application does with his toolbar at the bottom of the screen.
How can i do that?
Thank you
By default, a modal view controller is meant to take up the entire screen (on an iPhone/iPod, at least). Because of this, it covers whatever you have on screen at the time.
A view controller presented via modal segue is meant to live on its own. If you want to keep your Navigation and TabBar, then just use a push segue to present the new ViewController. Remember to use this kind of segue, your presenting controller needs to be part of a UINavigationController already.
Use this to push a ViewController. If it is a UINavigationController it will push its linked RootViewController by itsself.
Create a viewController to push: (Using Storyboard)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"LoginViewController"];
or (Using Code/Nibs)
LoginViewController *viewController = [[LoginViewController alloc] init]; //initWithNibNamed in case you are using nibs.
//in case you want to start a new Navigation: UINavigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
and push with:
[self.navigationController pushViewController:vc animated:true];
Also, if you are using Storyboards for the segues you can use this to do all the stuff. Remember to set the segue identifier.
[self performSegueWithIdentifier:#"pushLoginViewController" sender:self]; //Segue needs to exist and to be linked with the performing controller. Only use this if you need to trigger the segue with coder rather than an interface object.
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"pushLiftDetail"]) {
[[segue.destinationViewController someMethod:]];
segue.destinationViewController.someProperty = x;
}
}
I think you'll need to add a UITabBar to the modal view and implement/duplicate the buttons and functionality that your main bar has. The essence of a modal window is it has total control until it is dismissed.
You might try putting your UITabBarController into a NavBarController, but I'm not certain that this will work.
UITabBarController -> NavBarController -> Modal View

Creating and Removing UIViews Programmatically

I am learning how to manipulate view displays programmatically, I manage to display a new view in my appDelegate with the following block of code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController *navController = [[UINavigationController alloc] init];
loginController = [[LoginController alloc] init];
[navController pushViewController:loginController animated:NO];
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES; }
I have added a button in this view that will remove this current view and supposedly programmatically display a new view, however, I only managed to remove the view and not display the new view.
my code to display the second view is the following:
HomeController *homeView = [[HomeController alloc] init];
[self.window addSubview:homeView.view];
[homeView.view release];
Please advise.. I've been searching for hours to no avail, using Switch Views Programmatically, iPhone Views, removeSuperview..
Basically I want to create a simple login flow, at app start I will display my first view (login form), after successful login I want to discard the old view and display the second view which is my home page.
You are on the right track with using the UINavigationController. In fact, you are almost there.
You already have two view controllers - one for the login page, and one for the home page. In the didFinishLaunchingWithOptions:, push both controllers onto the UINavigationController's stack: first the "home" controller, then the "login" one. Once the login controller detects that the login has been successful, call popViewControllerAnimated: or popToRootViewControllerAnimated: to get to the home page.

Show view from storyboard chain

I have a chain in storyboard and I want to start (for example) second view when I have first launching app. I have some code, which only work in
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
method, if I put it in
- (void)viewDidLoad
method it's not work,
the code which show my other view is:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:#"someId"];
[vc setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
How can I show view, which have place in chain in storyboard when app have first launching?
Try your code in
-(void)viewDidAppear:(BOOL)animated.
For further information on the iOS viewcontroller lifecycle head over to UIViewController class reference
If you are using a navigation controller, you can simply push the second view onto the navigation stack. If you are not using a navigation controller, then you could force a segue to the next view from the loading.

How to switch page on iPhone?

HI, everyone,
I want to ask a question about the iPhone application. I am writing a program. The program will ask the user the enter some information and press enter, after that the program will process and get some information, then the program will display the tab page with 3 tabs.
However, I don't know how to switch the page after the user enter the information, I have write the following code.
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview: tabBarController.view]; // add the tab page to the view controller
MyViewController *aViewController = [[MyViewController alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
[self setMyViewController:aViewController];
[aViewController release];
UIView *controllersView = [myViewController view];
[window addSubview:controllersView]; // add the first page to the windows in order to let the user enter info.
[controllersView release];
// Override point for customization after application launch
[window makeKeyAndVisible];
}
If I add the tabBarController first, the controllersView will not appear, if I change the seuqence, it don't know how to make the controllersView disappear to let the tabBarController appears.
And the process is done in the MyViewController.m. Can I
1) remove the controllersView in the MyViewController.m after I complete all the process and
2) display the tabBarController.view ?
Thank you very much.
You need to use a UINavigationController as the root view-controller for your window. You can then push the first UIViewController (MyViewController) on as the top view.
(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
When its time for the tab view to appear push it onto the Navigation Controllers stack. To get back to your top view pop the ViewController off the stack
[self.navigationController popViewControllerAnimated:YES];