第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

如何使用按鈕標(biāo)簽快速訪問自定義單元格的內(nèi)容?

如何使用按鈕標(biāo)簽快速訪問自定義單元格的內(nèi)容?

桃花長相依 2019-12-26 08:51:30
我有一個在自定義單元格中具有自定義按鈕的應(yīng)用程序。如果選擇該單元格,它將顯示到詳細(xì)信息視圖,這是完美的。如果選擇單元格中的按鈕,則下面的代碼將單元格索引打印到控制臺中。我需要訪問所選單元格的內(nèi)容(使用按鈕)并將其添加到數(shù)組或字典中。我對此很陌生,因此很難找到如何訪問單元格的內(nèi)容。我嘗試使用didselectrowatindexpath,但是我不知道如何將索引強(qiáng)制為標(biāo)簽的索引...因此,基本上,如果每個單元格中有3個單元格帶有“ Dog”,“ Cat”,“ Bird”作為cell.repeatLabel.text,并且我選擇了第1行和第3行(索引0和2)中的按鈕,在數(shù)組/字典中添加“狗”和“鳥”。    // 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貢獻(xiàn)1982條經(jīng)驗(yàn) 獲得超2個贊

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


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

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

您將從按鈕標(biāo)簽獲得的標(biāo)簽。


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

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超3個贊

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


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


查看完整回答
反對 回復(fù) 2019-12-26
  • 3 回答
  • 0 關(guān)注
  • 459 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號