【问题标题】:UITableView in a UIViewController linked to another ViewController (DetailController)UIViewController 中的 UITableView 链接到另一个 ViewController (DetailController)
【发布时间】:2012-07-31 16:23:29
【问题描述】:

我在商店中有一个应用程序,它使用链接到 UIViewController (DetailController) 的 RootViewController,我正在开发一个基本上需要相同功能的新应用程序。但相反,我的新应用在 UIViewController 内有一个 UITableView,该 UIViewController 链接到 UIViewController。所以我想,我会将我的 RootViewController 代码复制并粘贴到这个新的 UIViewController 中。所以我已经链接了 TableView,将委托和数据源设置为 self,并且 TableView 显示了项目的标题(Hurrah)但是当被触摸时,不会去 DetailController?我使用 NSLog 来确定哪个部分不起作用,当然还有 didSelectRowAtIndexPath 方法……这是我的代码

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *theItem = [items objectAtIndex:indexPath.row];
    DetailController *nextController = [[DetailController alloc] initWithItem:theItem];
    [self.navigationController pushViewController:nextController animated:YES];
    [nextController release];

}

TableViewCell 只是突出显示蓝色并且没有链接到 DetailController。

提前致谢!

【问题讨论】:

  • 您是否正确设置了导航控制器?
  • 是的,完全连接起来了。 dataSource 和 delegate 都是 self
  • 导航控制器不需要数据源和委托,视图控制器是否在 UINavigationController 中具有表视图?把它放在你的 didSelect 方法中:NSLog(@"Navigation Controller: %@", self.navigationController);

标签: iphone xcode tableview viewcontroller


【解决方案1】:

“不工作”是否意味着它没有被调用,或者它没有推动视图控制器?如果是第一个,请确保正确设置了表视图委托。如果是第二个,请确保 nextController 和 self.navigationController 都不是 nil。

【讨论】:

  • 您好,感谢您的回复,我的意思是不推送视图控制器。我没有任何代码表明它们为零?
  • 可以添加断点检查,也可以使用NSLog打印值。
猜你喜欢
  • 1970-01-01
  • 2015-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多