detailview屏幕无法在tableview中使用pushViewController打开

时间:2012-09-06 08:32:03

标签: objective-c ios uitableview pushviewcontroller

我的项目中有一个标签栏,每个标签栏都有一个tableview。 我想在tableview中单击一行时打开一个详细信息屏幕,如下所示。但没有任何反应。 我正在做的错误在哪里。我应该如何设置逻辑。

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
DetailScreen *detail = [[DetailScreen alloc] initWithNibName:@"DetailScreen" bundle:nil];
 [self.navigationController pushViewController:detail animated:YES];
[detail release];

}

6 个答案:

答案 0 :(得分:2)

单击一个单元格时,有很多可能的原因没有发生。

  • 在此方法中加入一个断点。它甚至被称为?
  • 应用程序在断点处停止后,在初始化实例后转到控制台类型po detail。确保它不是(null)
  • 同时尝试键入po [self navigationController]以检查导航控制器是否存在。

你可能没有导航控制器。你是如何创建tabbarcontroller的?在界面构建器中或通过AppDelegate的didFinishLaunchingWithOptions:方法中的代码?

你做到了吗?

    YourViewController *yourVC = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil];

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:yourVC];

    self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController, nil];

答案 1 :(得分:1)

试试这个,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
     DetailScreen *detail = [[DetailScreen alloc] init];
     [self.navigationController pushViewController:detail animated:YES];
     [detail release];
}

答案 2 :(得分:1)

我猜你没有导航控制器

[self.navigationController pushViewController:detail animated:YES];

无效。

使用

[self.view addSubview:detail.view]

[self presentModalViewController:detail animated:YES];

代替

答案 3 :(得分:0)

如果您的项目是基于 UITabBarViewController 的应用程序,我不认为您可以使用pushViewController导航到另一个视图,除非您的项目中有 navigationController

答案 4 :(得分:0)

将视图控制器(包含控制器的表视图)添加到导航控制器中,然后开始使用

DetailScreen *detail = [[DetailScreen alloc] initWithNibName:@"DetailScreen" bundle:nil];
    [self.navigationController pushViewController:detail animated:YES];

答案 5 :(得分:-2)

[self.navigationController pushViewController:detail animated:YES];

而是将您的详细推送代码移动到另一个方法并调用:

[self performSelector:@selector(myMethod:) withObject:nil]