[英]presenting ViewController with NavigationViewController swift
[英]Go to second viewcontroller in NavigationViewController
我有一個UINavigationController
,它指向一個UITableViewController
(項目列表),那里有一個從單元格到另一個UITableViewController
(用於編輯項目的屏幕)的序列。
在第一次運行該應用程序時,我想跳過第一個列表,然后立即轉到第二個屏幕,以編輯新項。
問題是我需要傳遞第一個UITableViewController
,因為我需要能夠返回到那個UITableViewController
(或者有沒有辦法設置后退按鈕指向的控制器?)。
我嘗試過和失敗的事情:
在UINavigationController
上設置一個布爾值shouldPresentNewItem
,如果viewDidLoad
設置為true
,則在viewDidLoad
中設置第一個UITableViewController
,同時設置一個布爾值,這樣我就可以進入編輯屏幕了。
在UINavigationController
的viewDidLoad
使用self.navigationController!.popToViewController(arr[index] as UIViewController, animated: true)
。 由於self.navigationController
為nil
因此產生了錯誤。 (我不知道為什么會這樣)
如何才能做到這一點?
在導航控制器中設置一些布爾值,指示您將要顯示編輯屏幕,而在viewDidLoad
只需推送沒有動畫的編輯視圖控制器即可:
- (void) viewDidLoad {
[super viewDidLoad];
if (self.presentEditScreen) {
self.presentEditScreen = NO;
EditViewController *e = [[DetailViewController alloc] init];
[self pushViewController:e animated:NO];
}
}
最簡單的方法是。 只是從第二個視圖推到第一個視圖
firstViewController *objFirstViewController = [[firstViewController alloc]initWithNibName:@"firstViewController" bundle:nil];
[self.navigationController pushViewController:objFirstViewController animated:No];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.