簡體   English   中英

如何使后退按鈕始終轉到上一個視圖控制器

[英]How to have a back button always go to the previous view controller

我有多個視圖,其中一些是tabBarControllers的一部分,並且這些視圖正在推送到一個名為View2視圖控制器。 回到顯示view2的視圖時,如何回到標簽欄中的特定標簽,而不是第一個標簽?

我對返回到第一個視圖的按鈕的操作是

-(IBAction)goBackButton:(id)sender
{
    ViewController *firstView = [myStoryboard instantiateViewControllerWithIdentifier:@"view1"];
    [self presentViewController:firstView animated:YES completion:nil];
}

因此,ViewController是選項卡欄中第一個視圖的類,並且tabBarController的標識符為“ view1”

如果已按下 View2則您的后退按鈕操作應調用:

[self.navigationController popViewControllerAnimated:YES];

如果View2模式的,則您的后退按鈕操作應調用:

[self dismissViewControllerAnimated:YES completion:nil];

並且無論哪個場景稱為View2都會重新出現。

暫無
暫無

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

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