天天看点

iphone 程序自动登陆

场景介绍

app 里有一个有一个UITabBarController,在进入UITabBarController之前要验证用户是否已经登陆,如果没有登陆就弹出一个对话框,让用户输入登陆信息。

实现方式

1.在appDelegate。h里声明一个变量,用来绑定UITableController:

UITabBarController *tabbarController;

2.在appDelegate。m里添加如下方法

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after app launch    

   [window addSubview:tabbarController.view];

   [window makeKeyAndVisible];}

//背景图片

    window.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"wallpaper.png"]];

    [UIApplication sharedApplication].statusBarHidden = NO;

 //如果没有登录,就执行如下方法啊:

loginViewController *login = [[loginViewControlleralloc] initWithNibName:@"loginViewController"bundle:[NSBundlemainBundle]];UINavigationController *nav = [[UINavigationControlleralloc] initWithRootViewController:login];

[self.tabbarControllersetModalTransitionStyle:UIModalTransitionStyleCoverVertical];

[self.tabbarControllerpresentModalViewController:nav animated:YES];

3.在弹出的View的login执行方法里最后执行如下方法

-(IBAction)login

{

NSLog(@"login press");

[selfdismissModalViewControllerAnimated:YES];