【问题标题】:Segue from Table View Cell xib with disclosure Indicator to storyboard从 Table View Cell xib 与披露指示符转至情节提要
【发布时间】:2014-07-25 14:12:49
【问题描述】:

我是 iOS 编程新手,但遇到了问题。我在单独的 xib 文件中有一个带有披露指示器的自定义表格视图单元格,我想在用户点击单元格时调用情节提要中的视图控制器。

这是自定义的表格视图单元格:

这是显示自定义表格单元格的表格视图(类:TableViewController)和我想在用户点击自定义表格视图单元格时调用的视图(类:ViewController):

我要调用的视图是否必须位于单独的 xib 文件中,或者我可以将它放在我的情节提要中吗?最好的解决方案是什么?

【问题讨论】:

    标签: ios uitableview xcode5


    【解决方案1】:

    只需使用表格视图的 didSelectRoWAtIndexPath 方法......做这样的事情......

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        NSString* viewType = @"YourVCIdentifier";//u can have ContactVC or NavC as other options depending on ur condition
        UIViewController* viewController = [storyboard instantiateViewControllerWithIdentifier:viewType];
    
        [self.navigationController pushViewController:viewController animated:YES];
    
    
    }
    

    这样就可以了

    【讨论】:

      【解决方案2】:

      使用 UITableViewDelegate 方法

      - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

      并手动推送视图控制器。 为情节提要中的视图控制器分配情节提要 ID,然后执行以下操作:

      - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
      {
      
          UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
          UIViewController *destVC = [storyboard instantiateViewControllerWithIdentifier:@"your_view_controller_storyboard_ID"];
          [self.navigationController pushViewController:destVC animated:YES];
      }
      

      这是您为视图控制器分配情节提要 ID 的地方:

      并且不要忘记将您的视图控制器设置为您的 tableView 委托:)

      【讨论】:

        猜你喜欢
        • 2020-10-02
        • 1970-01-01
        • 2014-05-23
        • 2012-02-13
        • 1970-01-01
        • 1970-01-01
        • 2020-06-02
        • 2012-06-29
        • 2017-04-06
        相关资源
        最近更新 更多