我有一个工作项目,其中一个屏幕是例如ViewController 1 - tableView。在 ViewController 1 中选择一行后,我正在尝试传递数据并导航到ViewController 2。我添加了以下代码:
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
dvController.selectedItem = selectedItem;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
但它没有传递给ViewController 2。我认为问题出在 navigatorController 上。我应该在哪里添加它?到 ViewController 1 的 xib 文件?或 mainAppDelegate - 我不想碰它,因为它已经在使用它的设置......
我在 appDelegate 中声明了 UINavigationController *navigationController
我应该检查什么?
在对代码进行一些更改后(感谢@Vakul Saini)appDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.View1 = [[startSearching alloc] initWithNibName:@"StartSearching" bundle:nil];
self.currentNC = [[UINavigationController alloc] initWithRootViewController:self.View1];
//this line start the startSearching at the begining and its passing to //secondViewController
self.window.rootViewController = self.currentNC;
// 但是这一行是从原始起始页面开始的,但是视图的转移 // 不起作用
[self.window setRootViewController: self.viewController];
appDelegate.h
@property (strong, nonatomic) startSearching *View1;
@property (strong, nonatomic) UINavigationController *currentNC;
开始搜索.m
detailCon *detailCo =[[detailCon alloc] initWithNibName: @"detailView" bundle: [NSBundle mainBundle]];
[detailCon release];
UINavigation *currentNC1 = [[AppDelagate sharedInstance] currentNC];
[currentVC1 pushViewController:detailCo animated:YES];