代码之家  ›  专栏  ›  技术社区  ›  bugfixr

从TableView行单击时,将不显示详细视图

  •  0
  • bugfixr  · 技术社区  · 15 年前

    我的应用程序委托创建一个动态tabBarController并向其添加两个视图控制器。其中一个包含TableView。

    从这个表视图中,我希望用户能够单击每个项目上的蓝色箭头按钮,并获得有关它的更多详细信息。这是一件很标准的事。。。下面是我要做的代码:

    -(void)tableView: (UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *) indexPath {
        [self tableView:tableView didSelectRowAtIndexPath:indexPath];
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        // Navigation logic may go here. Create and push another view controller.
        [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
            if (self.switchView == nil) {
                SwitchViewController *viewController = [[SwitchViewController alloc] initWithNibName:@"SwitchViewController" bundle:[NSBundle mainBundle]];
                self.switchView = viewController;
                [viewController release];       
            }
    
        [self.navigationController pushViewController:self.switchView animated:YES];
        self.switchView.title = @"Test Title";
    
    }
    

    现在,我的SwitchViewController只是一个带有按钮的空白视图。 我可以设置一个断点来查看所有正在执行的代码,但iPhone屏幕根本没有改变。

    有什么建议吗?我确信这是一个基本的东西,因为我对iOS开发还很陌生。

    1 回复  |  直到 15 年前
        1
  •  0
  •   John Lemberger    15 年前

    从你在评论中对Vladmir问题的回答来看,很明显你没有初始化UINavigationController。所以试试这样的方法:

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tableViewController];
    

    然后将navController添加到tabBarController,而不是tableViewController。