天天看點

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