你好,我有同样的问题,我尝试了你的解决方案,但它没有帮助我在我的情况下.. 我没有得到例外,但观点没有改变..
我的代码如下
printf("hi");
//Get the selected country
NSString *selectedCountry = [listOfItems objectAtIndex:indexPath.row];
//Initialize the detail view controller and display it.
DetailViewController *aSecondView = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
// aSecondView.selectedCountry = selectedCountry;
[self.navigationController pushViewController:aSecondView];
[aSecondView release];
aSecondView = nil;
printf("bye..");
hi和bye都被打印但视图没有变化.. 我浪费了2天左右.. 请帮帮我..
答案 0 :(得分:1)
检查nib名称。你是如何为详细视图创建nib文件的?在你的情况下默认创建为DetailViewController。因此更改initWithNibName。你为什么设置aSecondView = nil?
正如kovpas所说,你将控制器从UIViewController而不是UINavigationController子类化,你使用presentModalViewController。用于实现导航控制器将此代码放在您的委托类
中- (void)applicationDidFinishLaunching:(UIApplication *)application {
UINavigationController *nvcontrol =[[UINavigationController alloc] initWithRootViewController:viewController];
[window addSubview:nvcontrol.view];
[window makeKeyAndVisible];
}
答案 1 :(得分:0)
如果您取消评论您的评论代码...我在您的代码中找到的另一个问题...交换这两行......
aSecondView.selectedCountry = selectedCountry;
[self.navigationController pushViewController:aSecondView];
尝试把它像这样
[self.navigationController pushViewController:aSecondView];
aSecondView.selectedCountry = selectedCountry;
如果您取消注册该行,则可能会产生问题
答案 2 :(得分:0)
似乎,您从UIViewController继承您的控制器而不是UINavigationController
尝试使用
[self presentModalViewController:aSecondView animated:YES];
点击
[self dismissModalViewControllerAnimated:YES];