亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用按鈕標簽快速訪問自定義單元格的內容?

如何使用按鈕標簽快速訪問自定義單元格的內容?

桃花長相依 2019-12-26 08:51:30
我有一個在自定義單元格中具有自定義按鈕的應用程序。如果選擇該單元格,它將顯示到詳細信息視圖,這是完美的。如果選擇單元格中的按鈕,則下面的代碼將單元格索引打印到控制臺中。我需要訪問所選單元格的內容(使用按鈕)并將其添加到數組或字典中。我對此很陌生,因此很難找到如何訪問單元格的內容。我嘗試使用didselectrowatindexpath,但是我不知道如何將索引強制為標簽的索引...因此,基本上,如果每個單元格中有3個單元格帶有“ Dog”,“ Cat”,“ Bird”作為cell.repeatLabel.text,并且我選擇了第1行和第3行(索引0和2)中的按鈕,在數組/字典中添加“狗”和“鳥”。    // MARK: - Table Viewoverride 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)") }
查看完整描述

3 回答

?
臨摹微笑

TA貢獻1982條經驗 獲得超2個贊

由于您在表格視圖中有1個部分,因此可以獲取如下的單元格對象。


let indexPath = NSIndexPath(forRow: tag, inSection: 0)

let cell = tableView.cellForRowAtIndexPath(indexPath) as! CustomCell!

您將從按鈕標簽獲得的標簽。


查看完整回答
反對 回復 2019-12-26
?
米脂

TA貢獻1836條經驗 獲得超3個贊

Swift 3 我只是使用按鈕標簽的超級視圖在@IBAction函數中獲取訪問單元的解決方案。


let cell = sender.superview?.superview as! ProductCell

var intQty = Int(cell.txtQty.text!);

intQty = intQty! + 1

let  strQty = String(describing: intQty!);

cell.txtQty.text = strQty


查看完整回答
反對 回復 2019-12-26
  • 3 回答
  • 0 關注
  • 462 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號