Я пытаюсь запустить действие для нажатия кнопки внутри ячейки представления таблицы. Следующий код находится в моем классе контроллера табличного представления.
Кнопка была описана как "да" в розетке в моем классе UITableViewCell, называемом requestCell.
Я использую Parse для сохранения данных и хочу обновить объект при нажатии кнопки. Мой массив objectsIds работает отлично, 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()
}
}
}