为 UITableView 中单击的静态单元格创建操作

Posted

技术标签:

【中文标题】为 UITableView 中单击的静态单元格创建操作【英文标题】:Create Action For Static Cell Clicked in 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()

【问题讨论】:

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

【讨论】:

以上是关于为 UITableView 中单击的静态单元格创建操作的主要内容,如果未能解决你的问题,请参考以下文章

从 collectionView 单元格中获取和更新 UITableView 单元格单击

UITableView 静态单元格作为子视图?

带有 Google SDK 的 UITableView 静态第一个单元格

UITableView 底部的静态单元格

Xcode 静态 UITableView 单元格在情节提要中为空白

使用 MoviePlayer 控制器在一个 UITableView 静态单元格中播放 .mp4