我想推送根視圖控制器。爲什麼這個代碼不工作?如何推送根視圖控制器?
RootController *rootController = [[RootController alloc]initWithStyle:UITableViewStylePlain];
[self.navigationController pushViewController:rootController animated:YES];
[rootController release];
我以前用過addSubview。
- (void)cancel {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad { // this is root view controller
[super viewDidLoad];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)];
self.navigationItem.leftBarButtonItem = cancelButton;
[cancelButton release];
}
RootController *rootController = [[RootController alloc]initWithStyle:UITableViewStylePlain];
UINavigationController *aNavigationController = [[UINavigationController alloc]initWithRootViewController:rootController];
self.naviController = aNavigationController;
[aNavigationController release];
[rootController release];
[self.view addSubview:[naviController view]];
而且我在導航欄中添加了取消按鈕以返回上一個視圖。它不起作用。 所以,我想推,而不是添加。
我們需要更多的上下文。怎麼了?期望什麼?你還在做什麼? – Moshe
http://stackoverflow.com/questions/6909619/how-can-i-go-back-to-the-previous-view-from-root-view這是我問的問題鏈接。 – user698200
你用什麼代碼回到前一個視圖? 「它不起作用」是什麼意思?什麼都沒發生?崩潰?設備開始吸菸? – Caleb