【发布时间】:2015-05-07 19:41:49
【问题描述】:
我正在尝试为在表格视图单元格中按下的按钮运行一个动作。以下代码在我的表视图控制器类中。
在我的 UITableViewCell 类中名为 requestsCell 的插座中,该按钮被描述为“是”。
我正在使用 Parse 保存数据,并希望在按下按钮时更新对象。我的 objectIds 数组工作正常, cell.yes.tag 还会将正确的数字打印到日志中,但是,我无法将该数字输入“已连接”函数以正确运行我的查询。
我需要一种方法来获取单元格的 indexPath.row 以找到正确的 objectId。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as requestsCell
// Configure the cell...
cell.name.text = requested[indexPath.row]
imageFiles[indexPath.row].getDataInBackgroundWithBlock{
(imageData: NSData!, error: NSError!) -> Void in
if error == nil {
let image = UIImage(data: imageData)
cell.userImage.image = image
}else{
println("not working")
}
}
cell.yes.tag = indexPath.row
cell.yes.targetForAction("connected", withSender: self)
println(cell.yes.tag)
return cell
}
func connected(sender: UIButton!) {
var query = PFQuery(className:"Contacts")
query.getObjectInBackgroundWithId(objectIDs[sender.tag]) {
(gameScore: PFObject!, error: NSError!) -> Void in
if error != nil {
NSLog("%@", error)
} else {
gameScore["connected"] = "yes"
gameScore.save()
}
}
}
【问题讨论】:
-
查看我的answer for a similar question,其中显示了多达 5 种不同的方法来解决您的问题。
标签: ios swift uitableview parsing