【问题标题】:Create Action For Static Cell Clicked in UITableView为 UITableView 中单击的静态单元格创建操作
【发布时间】:2015-06-06 15:23:51
【问题描述】:

当在 Swift 中单击其中一个单元格时,如何制作静态表格视图以创建操作?

我已经创建了一个像应用程序的常规菜单一样的静态表格,当单击其中一个单元格时,我可以直接创建一个 push segue。但与此同时,当我单击其中一个序列时,我希望运行以下函数。通过将单元格拖到情节提要中的 UITableView 中,创建操作选项不会出现。

    var goToProfiles = PFObject(className: "goToProfile")    
    goToProfiles["user"] = PFUser.currentUser()!.username
    goToProfiles["goToUser"] = usernameLbl.text
    goToProfiles.save()

【问题讨论】:

  • 如果您说明到目前为止您已经尝试过什么,具体来说,您不知道该怎么做,您更有可能得到答案。这就是这个网站的运作方式。
  • 这是我的首选方法:stackoverflow.com/a/9704127/654870

标签: ios swift uitableview


【解决方案1】:

如果您使用部分,您还需要查询它们。

override func tableView(tableView: UITableView, 
    didSelectRowAtIndexPath indexPath: NSIndexPath) {

    print(indexPath.section)
    print(indexPath.row)

    if indexPath.section == 1 && indexPath.row == 1 {
        // do something
    }

}

【讨论】:

    【解决方案2】:

    我通过以下代码找到了解决方案:

    override func tableView(tableView: UITableView,
        didSelectRowAtIndexPath indexPath: NSIndexPath) {
    
    
            if indexPath.row == 1 {
    
          //here you can enter the action you want to start when cell 1 is clicked
    
    
    
            }
    
    
    
    }
    

    【讨论】:

      【解决方案3】:

      对于 swift 3 的兼容性:

        func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
          //Your action here
       }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-04
        • 2023-04-05
        • 1970-01-01
        • 2012-05-05
        相关资源
        最近更新 更多