【问题标题】:Swift/parse : IBAction in a tableViewCell to make pfrelationSwift/parse:在 tableViewCell 中进行 IBAction 以进行 pfrelation
【发布时间】:2014-09-06 08:14:45
【问题描述】:

我想在 tableViewCell 中实现 IBAction。 tableView 显示用户列表,对于每个用户,我都有一个关注按钮。

follow方法需要指定要关注的用户是cell的用户。

我该怎么做?

 override  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell: AddFirendsTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)as AddFirendsTableViewCell

    let users:PFObject = self.userList.objectAtIndex(indexPath.row) as PFObject
   return cell
   }

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

    let users:PFObject = self.userList.objectAtIndex(indexPath.row) as PFObject




}

@IBAction func followUnfollow(sender: AnyObject) {

    //what should i put here ?


}



func follow (user :PFUser) {


    var relation : PFRelation = PFUser.currentUser().relationForKey("KfriendsRelation")
    relation.addObject(user)
    PFUser.currentUser().saveInBackgroundWithBlock { (succeed:Bool, error: NSError!) -> Void in
        if error != nil {
            println(error)
        }
    }

}

【问题讨论】:

    标签: uitableview swift parse-platform ibaction


    【解决方案1】:

    我对你的处理方式有点困惑,但我只是暂时了解一下。为了获得对单元格的引用,您可以使用以下行:

    let indexPath = tableView.indexPathForRowAtPoint(buttonPosition)
    

    然后,您可以使用索引路径来获取对单元格的引用,然后对它做您喜欢的事情:

    let cell = tableView.cellForRowAtIndexPath(indexPath)
    

    但是,我会亲自将 IBAction 移动到 AddFirendsTableViewCell 的单元格子类中,您已经可以访问所有单元格变量和值。这意味着每个单元格的工作方式都相同,您不必做一些奇怪的解决方法来尝试找出按下了哪个按钮。但这只是我的观点。希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-06-24
      • 2016-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多