I need a login viewcontroller,when log in,entry the tabbar controller,and the view in tabbarcontroller should get the data from the login viewcontroller and change the navigationbar(draged from nib)'s title,for example,show the user's name.I did it like :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[self.window addSubview:_tabbarController.view];
[self.window addSubview:_loginViewController.view];
[self.window makeKeyAndVisible];
return YES;}
I add two subview,so when I remove the loginviewcontroller,the root shows,in the LoginViewController.m,I did it like:
-(IBAction)ShangHaiButtonPressed:(id)sender{
[self.view removeFromSuperview];}
so how do i pass the value in login view to my tabbarcontroller?
Before remove from superview pass the value to tabbarcontroller
-(IBAction)ShangHaiButtonPressed:(id)sender{
[_tabbarController setUsername: [_loginViewController username]];
[_tabbarController setPassword: [_loginViewController password]];
[self.view removeFromSuperview];
}
I think it is not appropriate to remove the view directly. Why not use [_tabbarController presentModalViewController:_loginViewController]. and Dismiss it after button is pressed.
Related
I have a viewcontroller containing a TabController. Before this loads, I want a user to login so I can check what they have access to. In my AppDelegate, bot the rootViewController (with the tabs) and the LoginViewController are declared, and they're also wired up in IB:
I have this in my AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// [window addSubview:[rootController view]];
[window addSubview:[loginViewController view]];
[self.window makeKeyAndVisible];
return YES;
}
My plan was to dismiss the login form after authenticating and show the rootController, but the rootController displays straight away. I was going to do:
-(IBAction)DidClickLoginButton:(id)sender {
NotesAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.window addSubview:[delegate.rootController view]];
[self dismissModalViewControllerAnimated:YES];
}
Is there an easier way to do this? I can't see why the LoginViewController isn't presented.
EDIT: Eventually got this working by adding it to the rootController in my AppDelegate's didFinishLaunchingWithOptions method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// [window addSubview:[rootController view]];
[self.window makeKeyAndVisible];
LoginViewController *loginViewController =[[LoginViewController alloc] initWithNibName:#"LoginView" bundle:nil];
[self.rootController presentModalViewController:loginViewController animated:YES];
return YES;
}
I think it's actually much easier to do things 100% programmatically rather than with Interface Builder. Either way, in application:didFinishLaunchingWithOptions:, you want to do something like this:
[rootViewController presentModalViewController:loginViewController animated:NO];
Then, after the user logs in, do:
[rootViewController dismissModalViewControllerAnimated:YES];
Yes it would. As you are adding the root controller view on the window, and this would make it appear above all (even above the login view) and then your login view gets dismissed behind the root view, which you cannot see.
EDIT:
One of the approach would be to have login controller above root in the beginning itself (root view controller presenting login view) and then happily dismiss the login view.
I need some help with modal view controllers, as I have not used Modal View Controllers before...
So this is how my application now is...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[_window addSubview:rootController.view];
rootController.selectedIndex =2;
NSLog(#"Displaying the APP delegate");
[self.window makeKeyAndVisible];
return YES;
}
I have a view for Login, titled LoginViewController . I want this to appear first as the first view, and on clicking the Login button (IBAction), I want it to show rootController.selectedIndex =2;
(Please ignore the login check as of now). I just want the login view controller to appear at first, and dismiss itself if I press Login, and then take the screen to my rootController (which is a UITabBarController)
In the viewDidLoad method of the first view in the tabBar present the modal view as follows :
LoginViewController *lvc = [[LoginViewController alloc]initWithNibName:#"LoginViewController" bundle:[NSBundle mainBundle]];
[self presentModalViewController:lvc animated:YES];
[lvc release];
To dismiss the modalView, in the IBAction of the login button just put in the following code :
[self dismissModalViewControllerAnimated:YES];
I have successfully shown a view upon launch that authenticates a user. Upon success, I want the presentModalViewController to no longer be visible and deallocate properly.
My code is as follows:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the tab bar controller's view to the window and display.
[self.window addSubview:tabBarController.view];
Overview *overview = [[Overview alloc] initWithNibName:#"Overview" bundle:nil];
[self.tabBarController presentModalViewController:overview animated:YES];
[overview release];
[self.window makeKeyAndVisible];
return YES;
}
In your modal viewcontroller you need a piece of code doing:
[self dismissModalViewControllerAnimated:YES];
I was doing great till now with my tabbar application.
But now I have to add one viewcontroller at start of application and based on selection on that view have to go on specific tab of my tabcontroller.
What I thought to do is change my start up in AppDelegate to new viewcontroller instead of tabbarcontroller, which I did like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Add the view controller's view to the window and display.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
And then call a appdelegate method on button click in new startup view to switch to tabbarcontroller, code is:
-(IBAction)btnTab:(id)sender{
[(AppDelegate *) [[UIApplication sharedApplication] delegate] ChangeView];
}
//ChangeView method in AppDelegate:
-(void)ChangeView{
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
}
But problem is I can't see my new view with button on startup, just a blank view is coming...any suggestions?
I'm pretty sure that your tabBarController is nil.
How can I accomplish the following:
When my app loads a UIView will show 4 buttons
Clicking on a button will load a UITabBarController (not a UIView with a UITabBar) that can display multiple views.
This seems challenging to me, because in order for me to use the UITabBarController I need to add this to the window's subview in my appDelegate. By doing so, my app automatically will load with the UITabbarController in the root view.
You don't need to add the UITabBarController in the application delegate, that's just the most common way to use it. You can have your initial view use a simple UIViewController, then when the button is pressed load the UITabBarController (either programmatically or from a nib), and then display it.
The following is an example of what might be in your app delegate:
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// viewController is a UIViewController loaded from MainWindow.xib with a button that calls loadTabBarController
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
- (IBAction) loadTabBarController {
self.tabBarController = [[[UITabBarController alloc] initWithNibName:#"MyTabBarController" bundle:nil] autorelease];
[viewController.view removeFromSuperview];
[window addSubview:tabBarController.view];
}