Uitableview Swift/parse:tableViewCell中的iAction以建立pfrelation
我想在tableViewCell中实现iAction。 tableView显示了一个用户列表,对于每个用户,我都有一个follow按钮 follow方法需要指定要跟随的用户,即单元格的用户 我怎么能这样做Uitableview Swift/parse:tableViewCell中的iAction以建立pfrelation,uitableview,swift,parse-platform,ibaction,Uitableview,Swift,Parse Platform,Ibaction,我想在tableViewCell中实现iAction。 tableView显示了一个用户列表,对于每个用户,我都有一个follow按钮 follow方法需要指定要跟随的用户,即单元格的用户 我怎么能这样做 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell: AddFirendsTab
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)
}
}
}
我有点搞不懂你是怎么做的,不过我会带着它跑一会儿。要获取对单元格的引用,可以使用以下行:
let indexPath = tableView.indexPathForRowAtPoint(buttonPosition)
然后,您可以使用索引路径获取对单元格的引用,并因此对其执行您喜欢的操作:
let cell = tableView.cellForRowAtIndexPath(indexPath)
但是,我个人会将iAction移动到AddFirendsTableViewCell的cells子类中,在那里您已经可以访问所有的cells变量和值。这意味着每个细胞的工作方式都是一样的,你不需要做一些奇怪的工作来找出哪个按钮被按下了。但是,这只是我的看法。希望这会有所帮助