我目前正在开发一款应用程序,该应用程序从烂番茄API中检索电影列表并将其显示在表格中。我希望一旦我点击一行就显示一个UIViewController,这样我就可以显示一个详细的页面。
这是我的didSelectRowAtIndexPath代码。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
//UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:self]; // This line of code throws an exception for some reason.
[self.navigationController pushViewController:detailViewController animated:YES];
}
可能是我已经很长一段时间都没有睡觉但是我不能为我的生活弄清楚我哪里出错了。
PS。我正在使用arc。
答案 0 :(得分:2)
您确定您的导航控制器已初始化吗?
如果不是您在构建UIViewController
:
MyVc = [[MyVC alloc] initWithNibName:@"MyVC" bundle:nil];
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:myVc];
[_window addSubview:navCon.view];
答案 1 :(得分:0)
在AppDelegate.h文件中写下这些属性
@property (strong, nonatomic) YourFirstViewController *yourFirstController;
@property (nonatomic, retain) UINavigationController *navigationControl;
在AppDelegate.m文件中编写此代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.yourFirstViewController = [[YourFirstViewController alloc] initWithNibName:@"YourFirstViewController" bundle:nil]];
navigationController = [[UINavigationController alloc] initWithRootViewController:self.yourFirstViewController];
[self.window addSubview:[navigationController view]];
[self.window makeKeyAndVisible];
return YES;
}
我认为这会对你有所帮助。