Perform action when UITableViewCell is clicked

didselectrowatindexpath not called
uitableviewcell delegate
uitableviewcell button click swift 4
uitableviewcell pressed
uitableview selection
uibutton in uitableviewcell
uitableviewcell button action objective-c
uitableview single selection programmatically

I am making an tvOS app for the Apple TV but I have some problems with my UITableView. When I click on a UITableViewCell nothing happens. I am using targetForAction but it doesn't seem to work.

This is my code:

override func viewDidLoad() {

    self.tableView.dataSource = self
    self.tableView.delegate = self

let allData = ["Los Angeles","New York","San Fransisco"]

@IBOutlet weak var tableView: UITableView!

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return allData.count

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = UITableViewCell(style: .Default, reuseIdentifier: nil)
    cell.textLabel?.text = "\(allData[indexPath.row])"
    cell.targetForAction("buttonClicked:", withSender: self)
    return cell

func buttonClicked(sender:AnyObject) {
    print("button clicked!")

I found the solution. I had to add this function:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    print("selected cell \(indexPath.row)")

Handling Row Selection in a Table View, At this point, your app performs the action, such as displaying the details of the selected hiking trail: func tableView(_ tableView: UITableView, didSelectRowAt� In thsi code, we will learn how perform action on UITableView cell or when user click on cell of UITableView. We will also learn to pass data from one viewcontroller to other viewcontroller using s

Swift 5:

func tableView(_ tableView: UITableView, didSelectRowAtindexPath: IndexPath) {

How to get IndexPath of tableView …, override func tableView(_ tableView: UITableView, cellForRowAt indexPath: So how can I get the IndexPath of the selected row so I can do stuff with it in the useFruit() function? With changes above, you can write the action method as: Usually you make use of this method to prevent selection of a particular cell from taking place. Typically, you use “didSelectRowAtIndexPath” method, which is invoked after user selects a row, to handle the row selection and this is where you add code to specify the action when the row is selected.

Please use the UITableView Delegate method.

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {


Handling button tap inside UITableView Cell without using tag, Handling button tap inside UITableView Cell without using tag cover using delegate and closure to handle button click inside a tableview cell. awakeFromNib() // Initialization code // Add action to perform when the button� What I usually do is create a custom class of type UITableViewCell. In this type I store a pointer of whatever data that I use to back the action I want the cell (or a button on the cell) to perform: In this type I store a pointer of whatever data that I use to back the action I want the cell (or a button on the cell) to perform:

Segue from UITableViewCell Taps in Swift — Coding Explorer Blog, All we have to do is set up a segue, and treat it pretty much exactly like we did in in the “Accessory Action” section above, but I have not tested this yet. I just simply selected the UITableView from the Document Outline, and� iOS Tutorial on UITableViewCell - Learn to perform action on the click on UITableViewCell in swift 4 and XCode 9.

Navigate from UITableView cell to other ViewController using , We will cover following points in this video 1) Detect cell click or cell action in UITableView Duration: 25:30 Posted: Jun 9, 2018 If you use the “Accessory Action” one, that will be what happens if they tap on the accessory of the UITableViewCell. For instance, in Marco Arment ‘s Overcast App , on the right side of a podcast in the podcast episode list, there is a little “i” information symbol in the accessory view area.

Push segue from UITableViewCell to ViewController in Swift, To create a segue from a UITableViewCell to another View controller, we'll do it Click on it, go to its attribute inspector and give it “cell” as Identifier. Now if you wish to perform some operation when the segue occurs, you� Tapping one of the action buttons executes the handler block stored with the action object. This method returns an array of UITableViewRowAction objects representing the actions for the row. Each action you provide is used to create a button that the user can tap. Here’s what it looks like when a user swipes across the cell.

  • Do you have a segue from the UITableCell:s (or subclass of) of your UITableView to next view? Typically you do this via the storyboard, and prepares possible communication with next view by overloading the prepareForSegue method in your table view controller source. <-- since you fixed it yourself, never mind this then!