У меня есть приложение с пользовательской кнопкой в пользовательской ячейке. Если вы выберете ячейку, она перейдет к подробному представлению, что идеально. Если я выбираю кнопку в ячейке, приведенный ниже код выводит индекс ячейки в консоль.
Мне нужно получить доступ к содержимому выбранной ячейки (с помощью кнопки) и добавить их в массив или словарь. Я новичок в этом, поэтому изо всех сил пытаюсь узнать, как получить доступ к содержимому ячейки. Я пытался использовать didselectrowatindexpath, но я не знаю, как заставить индекс быть индексом тега...
Итак, в основном, если в каждой ячейке есть 3 ячейки с «Собака», «Кошка», «Птица» в качестве cell.repeatLabel.text, и я выбираю кнопки в строках 1 и 3 (индекс 0 и 2), он должен добавьте «Собаку» и «Птицу» в массив/словарь.
// MARK: - Table View
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return postsCollection.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: CustomCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell
// Configure the cell...
var currentRepeat = postsCollection[indexPath.row]
cell.repeatLabel?.text = currentRepeat.product
cell.repeatCount?.text = "Repeat: " + String(currentRepeat.currentrepeat) + " of " + String(currentRepeat.totalrepeat)
cell.accessoryType = UITableViewCellAccessoryType.DetailDisclosureButton
cell.checkButton.tag = indexPath.row;
cell.checkButton.addTarget(self, action: Selector("selectItem:"), forControlEvents: UIControlEvents.TouchUpInside)
return cell
}
func selectItem(sender:UIButton){
println("Selected item in row \(sender.tag)")
}