当单击tableview单元格上的按钮时,我想将一些单元格数据返回到按钮动作功能
TableView代码:
var cell = self.myTable.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell
var imgtext:AnyObject?
if (self.SearchController.active)
{
cell.textLabel?.text! = self.searchArray[indexPath.row]
cell.imageView?.image = decodedimage
let Acceptbutton : UIButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
Acceptbutton.frame = CGRectMake(40, 60, 60, 24)
let cellHeight: CGFloat = 44.0
Acceptbutton.center = CGPoint(x: view.bounds.width / 1.4, y: cellHeight / 2.0)
Acceptbutton.backgroundColor = UIColor.greenColor()
Acceptbutton.addTarget(self, action: "AcceptClicked:", forControlEvents: UIControlEvents.TouchUpInside)
Acceptbutton.setTitle("Accept", forState: UIControlState.Normal)
cell.addSubview(Acceptbutton)
按钮动作:
@IBAction func AcceptClicked(sender: AnyObject)
{
//How can I get the cell.textlabel.text here for that specific
// cell row that AcceptClick was triggered from?
// I've tried sender.IndexPath but it returns nil
}
我正在尝试将我的单元格数据传递到我的AcceptClicked函数中,以便我可以对特定单元格进行一些操作 .
1 回答
首先,您不希望
IBAction
在函数前面,因为它没有链接到Storyboard .其次,你可以使用这个:
如果只想要这一行:
您可以在
cellForRowAtIndexPath
中添加AcceptButton.tag = indexPath.row
并使用: