1

我目前正在开发一个应用程序,该应用程序从烂番茄 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。我正在使用弧。

4

2 回答 2

2

你确定你的导航控制器已经初始化了吗?

如果不是,您在构建的地方正确地缺少这样的东西UIViewController

MyVc = [[MyVC alloc] initWithNibName:@"MyVC" bundle:nil];
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:myVc];
[_window addSubview:navCon.view];
于 2012-07-20T12:40:01.550 回答
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;
    }

我想这会对你有所帮助。

于 2012-07-20T12:42:01.777 回答