Como acessar rapidamente o conteúdo de uma célula personalizada usando a tag button?
Eu tenho um aplicativo que possui um botão personalizado em uma célula personalizada. Se você selecionar a célula, ela segue para a exibição de detalhes, o que é perfeito. Se eu selecionar um botão em uma célula, o código abaixo imprime o índice da célula no console.
Preciso acessar o conteúdo da célula selecionada (usando o botão) e adicioná-los a uma matriz ou dicionário. Eu sou novo nisso, lutando para descobrir como acessar o conteúdo da célula. Tentei usar didselectrowatindexpath, mas não sei como forçar o índice a ser o da tag ...
Então, basicamente, se houver 3 células com 'Dog', 'Cat', 'Bird' como cell.repeatLabel.text em cada célula e eu selecionar os botões nas linhas 1 e 3 (Índice 0 e 2), ele deverá adicione 'Dog' e 'Bird' ao array / dicionário.
// 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)")
}