我有一个表格视图,在其中创建了一个标签和两个按钮。单击按钮时从标签获取文本时我陷入困境。我创建了一个数组列表,例如:
let arrayList: [String] = [ "aaa" , "bbb" , "ccc"]
我想要如果我点击按钮index[0]
我会得到“aaa”,如果index[2]
我会得到“ccc”
@IBOutlet weak var titleLable: UILabel!
@IBOutlet weak var infoButton: UIButton!
myCell.titleLable.text = self.arrayList[indexPath.row]
myCell.infoButton.tag = indexPath.row
myCell.infoButton.addTarget(self, action: "buttonClicked", forControlEvents: .TouchUpInside)
想拿到indexPath
,其中使用按钮标签单击按钮。
@IBAction func buttonClicked(sender:UIButton) {
let cell = tableView.cellForRowAtIndexPath(NSIndexPath.init(forRow: sender.tag, inSection: 0))
cell.myLabel.text = arrayList[sender.tag]
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)