-2

我想知道当你按下一个单元格时如何让 UITableView 转到不同的 ViewController 。到目前为止,我有这个代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath  *)indexPath
{
if (indexPath.row == 0) {       
}
}
4

2 回答 2

2

它是这样的:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath  *)indexPath
{
    if (indexPath.row == 0) {
        SomeViewController *newController = [[SomeViewController alloc] initWithNibName:nil bundle:nil];
        [self.navigationController pushViewController:newController animated:YES];
        [newController release]; // leave this line out if using ARC
    }
}

警告:只是在没有查看任何文档的情况下输入了上面的内容——如果在您将自己的视图控制器类名称替换为 之后它没有编译SomeViewController,请查找拼写错误等。

顺便说一句,有很多关于这个主题的文档,还有很多例子。如果上面的代码片段不能解决您的问题,请查看 iOS 视图控制器编程指南

于 2012-07-13T18:16:24.927 回答
0

您的问题是如此基本以至于无法回答,或者如果您不掌握一些基本的 iOS 概念,答案将毫无意义。我强烈建议您花几个小时在 iTunes(免费)上浏览 Standford iOS 编程课程的视频。

如果您是注册开发人员,Apple 还提供了许多来自 WWDC 的优秀视频,详细介绍了所涉及的基本设计模式。YouTube 上也有一些不错的视频。

当然还要查看源代码——来自 Apple、Standford 课程或本网站 ( http://www.raywenderlich.com/tutorials )上的许多优秀教程

于 2012-07-13T18:20:30.250 回答