Pass multiple parameters to addTarget

前端 未结 5 1956
小鲜肉
小鲜肉 2020-12-05 08:46

In my UITableViewCell I have a button. And I want to add action to it by passing multiple parameters in cellForRowAtIndexPath method.



        
5条回答
  •  囚心锁ツ
    2020-12-05 09:04

    You can use the tag property on the UIButtons's titleLabel and UIImageView to add additional parameters

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
    {
    let cell = tableView.dequeueReusableCellWithIdentifier("CartCell", forIndexPath:indexPath) as! CartTableViewCell
    cell.buyButton.tag = (indexPath.section*100)+indexPath.row
    cell.buyButton.imageView.tag = 2
    cell.buyButton.titleLabel.tag = 3
    cell.buyButton.addTarget(self, action: "btnBuy_Click:", forControlEvents: .TouchUpInside)
    }
    

提交回复
热议问题