簡體   English   中英

如何解除多個presentModalViewControllers並返回根Tab Bar控制器?

[英]How to dismiss multiple presentModalViewControllers and get back to the root Tab Bar controller?

我有一個應用程序,在啟動時顯示presentModalViewController。

- (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 *overviewViewController = [[Overview alloc] initWithNibName:@"Overview" bundle:nil];
    [self.tabBarController presentModalViewController:overviewViewController animated:YES];
    [overviewViewController release];
    [self.window makeKeyAndVisible];
    return YES;
}

一旦顯示overviewController,用戶就可以登錄或注冊。 如果他們選擇登錄,那么我正在使用另一個允許他們登錄的presentModalViewController:

  -(IBAction) btnLoginPressed{

//  [self dismissModalViewControllerAnimated:YES];
    Login *loginOverView = [[Login alloc] initWithNibName:@"Login" bundle:nil];
    [self presentModalViewController:loginOverView animated:YES];
    [loginOverView release];


}

但是在成功登錄后,我希望presentModalViewController都消失,這樣我就可以回到根控制器,這是一個標簽欄控制器。

我試圖做以下但它不起作用:

-(IBAction) btnSubmitLoginPassword{

    //make web service call
//  [self dismissModalViewControllerAnimated:YES];
    [self.tabBarController dismissModalViewControllerAnimated:YES];
}

現在在我的谷歌搜索中,我遇到了一些我不熟悉的代表概念。 有人可以花時間幫助我解決困境。

提前致謝

視圖控制器按堆棧組織。 您可以使用UINavigationController方法popToRootViewControllerAnimated:或popToViewController:animated:來控制從堆棧頂部彈出的視圖數。

您可以通過應用程序委托訪問UINavigationController實例。

將所有視圖控制器彈出到根視圖控制器:(我認為這就是你要問的)

UIApplicationDelegate* delegate = [[UIApplication sharedApplication] delegate];
[delegate.navigationController popToRootViewControllerAnimated:YES];

要將所有視圖控制器彈出到堆棧中的已知視圖控制器:

UIApplicationDelegate* delegate = [[UIApplication sharedApplication] delegate];
[delegate.navigationController popToViewController:popToViewController animated:YES];

添加id delegate; @property (nonatomic, retain) id delegate; 在您的Overview.h中。 在Overview.m中添加@synthesize delegate 然后在initWithNibName:bundle之后添加以下內容:

[overviewViewController setDelegate: self];

為您的Login類做同樣的事情:添加id delegate; @property (nonatomic, retain) id delegate; 在你的Login.h中。 在Login.m中添加@synthesize delegate 然后在initWithNibName:bundle之后添加以下內容:

[overviewViewController setDelegate: self];

在Overview.m中添加以下方法:

- (void)dismissLoginView {
    [self dismissModalViewControllerAnimated: NO];
    [delegate dismissModalViewControllerAnimated: YES];
}

將您的-(IBAction) btnSubmitLoginPassword

-(IBAction) btnSubmitLoginPassword {
    [delegate dismissLoginView];
}

我沒有測試過。 我希望它有效! 什么時候不知道。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM