将多个参数传递给addTarget [英] Pass multiple parameters to addTarget
本文介绍了将多个参数传递给addTarget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的UITableViewCell
中,我有一个按钮.我想通过在cellForRowAtIndexPath
方法中传递多个参数来对其添加操作.
In my UITableViewCell
I have a button. And I want to add action to it by passing multiple parameters in cellForRowAtIndexPath
method.
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CartCell", forIndexPath:
indexPath) as! CartTableViewCell
cell.buyButton.addTarget(self, action: self.buyButton(indexPath, 2, 3 ,4 , 5, 6), forControlEvents: .TouchUpInside)
}
推荐答案
也许您可以做这样的事情
May be you can do something like this
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.addTarget(self, action: "btnBuy_Click:", forControlEvents: .TouchUpInside)
}
func btnBuy_Click(sender: UIButton) {
//Perform actions here
let section = sender.tag / 100
let row = sender.tag % 100
let indexPath = NSIndexPath(forRow: row, inSection: section)
self.buyButton(indexPath, 2, 3 ,4 , 5, 6)
}
根据您的要求创建标签值并保持其完整性.
Create tag value according to you'r requirement and maintaint it's integrity too.
这篇关于将多个参数传递给addTarget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文