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

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

表格視圖單元格中的UIButton操作

表格視圖單元格中的UIButton操作

iOS
呼喚遠方 2019-10-17 16:14:50
我正在嘗試為在表格視圖單元格中按下的按鈕運行操作。下面的代碼在我的表視圖控制器類中。在我的UITableViewCell類的稱為requestCell的插座中,該按鈕已被描述為“是”。我正在使用“解析”來保存數據,并且想在按下按鈕時更新對象。我的objectIds數組可以正常工作,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()        }    }}
查看完整描述

3 回答

?
慕慕森

TA貢獻1856條經驗 獲得超17個贊

簡單易用的方法來檢測按鈕事件并執行某些操作


class youCell: UITableViewCell

{

    var yourobj : (() -> Void)? = nil


    //You can pass any kind data also.

   //var user: ((String?) -> Void)? = nil


     override func awakeFromNib()

        {

        super.awakeFromNib()

        }


 @IBAction func btnAction(sender: UIButton)

    {

        if let btnAction = self.yourobj

        {

            btnAction()

          //  user!("pass string")

        }

    }

}


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

    {

        let cell = youtableview.dequeueReusableCellWithIdentifier(identifier) as? youCell

        cell?.selectionStyle = UITableViewCellSelectionStyle.None


cell!. yourobj =

            {

                //Do whatever you want to do when the button is tapped here

                self.view.addSubview(self.someotherView)

        }


cell.user = { string in

            print(string)

        }


return cell


}


查看完整回答
反對 回復 2019-10-17
  • 3 回答
  • 0 關注
  • 427 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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