【问题标题】:UITableView with multiple viewcontollers具有多个视图控制器的 UITableView
【发布时间】:2010-02-27 22:25:51
【问题描述】:

我刚刚用行星填充了我的 UITableView。我希望每个单元格单击以打开一个新的 Xib(如果这听起来像是错误的方法,请直接指示)。我可以让第二个视图控制器工作,它让第三个视图控制器和第四个视图控制器工作?谢谢。

【问题讨论】:

  • 你能从你的 tableView:didSelectRowAtIndexPath: 方法中发布代码吗?如果您可以让第二个视图控制器正常工作,那么其余的应该也可以正常工作。
  • 查看 UINavigationController。它就是为此而设计的。

标签: iphone uitableview xib


【解决方案1】:

将您的主视图控制器(带有表格的那个)放在 UINavigationController 中。然后,当用户选择一行时,将一个新的视图控制器推送到它上面。

【讨论】:

    【解决方案2】:

    以下功能会有所帮助。正如 Ben Gottlieb 所说,您的主视图控制器需要位于 UINavigationController 中。您需要为 didSelectRowAtIndexPath 实现委托方法,这是您为新视图创建新控制器并加载它的地方。

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
            YourViewController *controller =  [[YourViewController alloc] initWithNibName:@"YourViewController"bundle:nil];         
            [[self navigationController] pushViewController:yourViewController animated:YES];   
            [yourViewController release]; // don't leak memory
            }
    

    您可以根据行号决定加载哪个笔尖。

    【讨论】:

    • 感谢 Neilngils 和 Ben。我玩弄它并添加了一个 IF 语句,不确定这是否是正确的方法,但它有效。 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { int RowCount = [indexPath row]; if (RowCount == 0){ EarthViewController *earthViewController = [[EarthViewController alloc] initWithNibName:@"EarthViewController"bundle:nil]; [[self navigationController] pushViewController:earthViewController 动画:YES]; [earthViewController 发布]; // 不要泄漏内存 } else if (RowCount ==1){ .....
    猜你喜欢
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多