I have a table view where I have created a label and two buttons. I am stuck while getting the text from the label on button click. I have created an array list like:
let arrayList: [String] = [ "aaa" , "bbb" , "ccc"]
I want if I click the button on index[0]
I shall get "aaa" and if index[2]
I shall get "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)
Try to get
indexPath
, where the button is clicked using the Button Tag.In your Table View Controller
In your Table View Cell
Firstly, define a protocol:
And then:
you need to do like
swift3
get action as
Swift2