UIButton not responding used in a custom UITableViewCell

后端 未结 6 1486
感动是毒
感动是毒 2020-12-20 19:29

I know this issue is already been asked few times in SO. Despite trying those out, I am still unable to solve my problem.

I am using a UITableView inside a UIViewCo

6条回答
  •  北海茫月
    2020-12-20 20:15

    I dont know what wrong in the code but i can suggest which i personally use and it works for me

    In BranchNearMeTableViewCell.swift

    @IBOutlet var btnDetails: UIButton!
    @IBAction func btnDetailsClick(sender: AnyObject) {
        tapButton?(self)
    }
    var tapButton: (UITableViewCell -> Void)?
    

    In Table view controller

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
            let cell = tableView.dequeueReusableCellWithIdentifier("branchNearTableCell") as! BranchNearMeTableViewCell
    
     cell.tapButton = {(user) in
                 //User will be tablecell here do whatever you want to do here
            }
    
    }
    

    So if you click on button in table cell this cell.tapButton will be called you can do whatever you want to do here

提交回复
热议问题