【问题标题】:How to use didSelectRowAtIndexPath to navigate to a specific tableview controller? (Swift)如何使用 didSelectRowAtIndexPath 导航到特定的 tableview 控制器? (迅速)
【发布时间】:2014-11-07 04:11:42
【问题描述】:

我知道我需要使用didSelectRowAtIndexPath,但尽管搜索我似乎找不到简单的解释。

我希望将TableView 用作其他 10 个ViewControllers索引,但是在找到解释如何将每个单元格链接到后续TableViewController 的简单资源时遇到问题。

【问题讨论】:

  • 正是您想要的?请清楚的简要说明。
  • 嘿!感谢您的回复 - 我有一个包含多个单元格的表格视图。当用户单击单元格时,我想导航到特定的 tableviewcontroller。
  • 而不是多个 tableViewController ,你必须只使用一个!并将数据传递给要在 didselectrowAtIndexPath 的单击事件中显示的 tableViewController。
  • 那么你在 tableviewController 中显示了什么!
  • 你真的需要 10 个不同的表格视图控制器(即 UITableViewController 的不同子类)吗?通常你定义一个或几个子类来导航,并根据所做的选择设置属性,即在 prepareForSegue 中。

标签: ios cocoa-touch swift didselectrowatindexpath


【解决方案1】:

试试这个:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    println("You selected cell #\(indexPath.row)!")

    // Show your screen here 
}

【讨论】:

    【解决方案2】:

    如果您正在获取bodyParts 的字典,那么您应该像这样使用: 例如

    NSDictionary *bodyparts; //containg data from database
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    
        let tblView = self.storyboard?.instantiateViewControllerWithIdentifier("Identifier") as UITableViewController
        switch(indexPath.row)
        {
            //data is array of tableviewcontorller
        case 0:
            tblView.Data = [bodyparts objectForKey:@"Arms"];//if You are getting array for key "Arms"
            break;
        case 1:
            tblView.Data = [bodyparts objectForKey:@"Legs"];
            break;
        and so on....
        default:
            break;
        }
    }
    

    您必须在情节提要中设置情节提要标识符

    【讨论】:

      猜你喜欢
      • 2020-06-09
      • 1970-01-01
      • 2016-02-24
      • 2018-03-21
      • 2015-05-10
      • 2017-12-26
      • 2012-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多