vuz*_*zum 2 uinavigationcontroller tableview viewcontroller ios
我正在尝试将一个UIViewController (AddProjectViewController)添加到一个导航控制器(navigationController),它有一个tableView设置为root,但它不起作用.
这就是我设置文件的方式:http://d.pr/y8rt
代码在ProjectsController.m- 请帮助:(
run*_*mad 16
好的,所以我先向你解释一下你做错了什么:
// You're not allocating the view here.
AddProjectViewController *nextController = addProjectViewController;
// When allocated correctly above, you can simple push the new controller into view
[self.navigationController pushViewController: (UIViewController *)addProjectViewController animated:YES];
Run Code Online (Sandbox Code Playgroud)
推送的视图控制器将自动继承super(推送它的视图控制器)导航栏(这意味着您可以在子视图控制器中对self.navigationController进行调用,因为UINavigationController只是UIViewController的子类(因此是UITableViewController).
这是你需要做的:
// Allocate AddProjectViewController
AddProjectViewController *addProjectViewController = [[AddProjectViewController alloc] init];
// Adds the above view controller to the stack and pushes it into view
[self.navigationController pushViewController:addProjectViewController animated:YES];
// We can release it again, because it's retained (and autoreleases in the stack). You can also choose to autorelease it when you allocate it in the first line of code, but make sure you don't call release on it then!
[addProjectViewController release];
Run Code Online (Sandbox Code Playgroud)
但是,对于您要做的事情,以模态方式呈现视图控制器会更好,这意味着您必须将其保存在导航控制器中.这是如何做:
// Allocate AddProjectViewController
AddProjectViewController *addProjectViewController = [[AddProjectViewController alloc] init];
// Create a navigation controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addProjectViewController];
// Release the view controller that's now being retained by the navigation controller
[addProjectViewController release];
// Adds the above view controller to the stack and present it modally (slide from bottom)
[self presentModalViewController:navigationController animated:YES];
// Release the navigation controller since it's being retained in the navigation stack
[navigationController release];
Run Code Online (Sandbox Code Playgroud)
请注意,您需要在AddProjectViewController类中创建UIBarButtonItems.
我已更新您的代码并将其上传到此处:http://dl.dropbox.com/u/5445727/Zum.zip
希望它有所帮助,你需要查看这里的评论,我没有将它们转移到你的项目中.祝好运 :)
| 归档时间: |
|
| 查看次数: |
22891 次 |
| 最近记录: |