帮助Modal View Controller&登录

时间:2011-06-22 17:35:29

标签: iphone objective-c cocoa-touch modalviewcontroller loginview

我需要一些模态视图控制器的帮助,因为我之前没有使用模态视图控制器......

所以这就是我现在的应用程序......

- (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;

}

我有一个登录视图,标题为LoginViewController。我希望首先将其显示为第一个视图,点击Login button (IBAction)后,我希望它显示为rootController.selectedIndex =2;

(请忽略截至目前的登录检查)。我只想让登录视图控制器首先出现,如果我按下登录,则自动关闭,然后将屏幕带到我的rootController(这是一个UITabBarController

1 个答案:

答案 0 :(得分:0)

在tabBar中第一个视图的viewDidLoad方法中显示模态视图如下:

LoginViewController *lvc = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:[NSBundle mainBundle]];

[self presentModalViewController:lvc animated:YES];

[lvc release];

要关闭modalView,在登录按钮的IBAction中只需输入以下代码:

[self dismissModalViewControllerAnimated:YES];