Swift UITableView didSelectRowAtIndexPath not getting called

tableview didselectrowatindexpath not called swift 4
didselectrowatindexpath not called custom cell
did select row at: indexpath swift 4
uisearchcontroller didselectrowatindexpath not working
tableview on select swift
uitableview single selection swift
tableview select row
uitableview selection

New to IOS development and am having trouble with handling cell selection on a table. Whenever I select, the method is not getting called below - any idea why?

My project structure is: View Controller -> View -> Table View

The below code demonstrates the method calls. The others get called no problem! I know touch is working as pull down successfully refreshes and on clicking a cell it does become highlighted.

import UIKit

class ViewController: UIViewController, UITableViewDelegate
{

   let blah = ["blah1"]

   //How many sections are in the table?
   func numberOfSectionsInTableView(tableView: UITableView) -> Int {
      return 1
   }

   //How many rows? (returns and int)
   func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
      return blah.count
   }

  //table contents for each cell?
  //Each time this is called it'll return the next row and thus build a table...
  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
      print("Populating each cell of table view!\n")
      tableView.rowHeight = 80.0
      var cell = UITableViewCell()

      var(a) = blah[indexPath.row]
      var image : UIImage = UIImage(named: a)!
      cell.imageView.image = image

      return cell
  }



  //Code Cell Selected
  func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
      println("You selected cell #\(indexPath.row)!")

  }


  func tableView(tableView: UITableViewDelegate, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
     print("wananananaanan" )
     println("You deselected cell #\(indexPath.row)!")

  }




  override func viewDidLoad() {
     super.viewDidLoad()

     // Do any additional setup after loading the view, typically from a nib.

  }

  override func didReceiveMemoryWarning() {
     super.didReceiveMemoryWarning()
     // Dispose of any resources that can be recreated.
  }
}

You have to set an @IBOutlet to the tableView in you ViewController and set as it's delegate and dataSource to you can see the data an respond to changes in the tableView.

Something like this :

override func viewDidLoad() {
    super.viewDidLoad()

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

And implements the UITableViewDataSource protocol too.

Or you can too in the Interface Builder set the ViewController as it's delegate and dataSource (more easy to do I think) and avoid to set manually in code like above. Is up to you.

I hope this help you.

didSelectRowAtIndexPath not being called (Swift), Remove the exclamation points: func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { }. Home » Ios » Swift UITableView didSelectRowAtIndexPath not getting called Swift UITableView didSelectRowAtIndexPath not getting called Posted by: admin February 24, 2018 Leave a comment

Everybody is mentioning to set dataSource and delete of the tableView. But after setting also not working fine then sometimes it may happen because of none or disable selection of table view.

To enable it Go to storyboard -> Select tableView -> click on the attribute inspector ->go to selector -> Select selection as single selection (or multiple selection according to the requirements.)

Please find attached screenshot for your suitability.

-didSelectRowAtIndexPath: not being called, It must be return indexPath , else -tableView:didSelectRowAtIndexPath: is not being called. If you added a gestureRecognizer on top of the UITableView, didSelectRowAtIndexPath will not get called. So you need to use gestureRecognizer delegate method to avoid touch in particular view. The didSelectRowAtIndex: method isn't called when the editing property of table is set to YES. By default this property is set to NO. Make sure the allowsSelection property is set to YES. By default it is.

SWIFT 3

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      // Do here
    }

Use the above delegate method in swift 3

UItableview didSelectRowAtIndexPath not being called, What should I do to make it correct? Thanks in advance. Tags: none (add) swift 5.1. If you added a gestureRecognizer on top of the UITableView, didSelectRowAtIndexPath will not get called. So you need to use gestureRecognizer delegate method to avoid touch in particular view.

didSelectRowAtIndexPath Not working - Swift, Both didSelectRowAtIndexPath and didDeselectRowAtIndexPath belong to the UITableViewDelegate protocol. For that protocol to work, the  UITableView didSelectRowAtIndexPath get instance of selected section tagged swift uitableview didselectrowatindexpath or ask not getting called On the

I faced the same issue when compared two identical code examples where one was working well and the other was not calling didSelectRowAtIndexPath

Take a look at two possible ways to solve the issue:

1) In the code itself:

@IBOutlet weak var table: UITableView!

override func viewDidLoad() {
    table.delegate = self
    table.dataSource = self 
//data source might be already set if you see contents of the cells
//the main trick is to set delegate
}

2) Using Storyboard or Document Outline (which was the problem in my case cause storyboard changes are not visible in .swift controller classes.

Open Document Outline and Control + Press your TableView you will see two outlets called "delegate" and "dataSource" drag them 1 by 1 to the containing ViewController (right onto the yellow circle)

That's it!

UITableView didSelectRowAtIndexPath: not being called on first tap , New to IOS development and am having trouble with handling cell selection on a table. Whenever I select, the method is not getting called  Swift UITableView didSelectRowAtIndexPath not getting called (4) Everybody is mentioning to set dataSource and delete of the tableView. But after setting also not working fine then sometimes it may happen because of none or disable selection of table view.

tableView:didSelectRowAtIndexPath: not working (Example), UITableView didSelectRowAtIndexPath: not being called on first tap working with Swift 3 in a class which isn't a UITableViewController and  UITableView didSelectRowAtIndexPath: not being called on first tap (8) SWIFT 2. Make sure you have this set to true: self.tableView.allowsSelection = true. Put this above your right after your viewDidLoad() and before the super.viewDidLoad()

didSelectRowAtIndexPath not being called, tableView:didSelectRowAtIndexPath: not working. ios · uitableview · interfacebuilder. As I now try to use more and more Interface Builder, I  If you added a gestureRecognizer on top of the UITableView, didSelectRowAtIndexPath is not called. if so you need to use gestureRecognizer delegate method to avoid touch in particular view.

[SideViewController][Storyboard example , Is your didSelectRowAtIndexPath function not being called? Here are some Not No Selection . You can also make this change in Swift code: tableview. Re: UItableview didSelectRowAtIndexPath not being called Level 8 (5,845 points) OOPer Feb 23, 2020 2:42 PM ( in response to mwmv )

Comments
  • did you set yourself as the table views delegate?
  • Or instead of subclassing UIViewController, use UITableViewController - then you get a lot of functionality for free. For example the UITableView will be already setup for you with the delegates pointing to your view controller.
  • Thank you, that worked perfectly! (I went with the quick option of setting the View Controller as delegate outlet.
  • the .delegate = self completely resolved this issue for me. I'm suprised that I did not do this before. Looks like table views can pack tons of features without setting this delegate value.
  • Fellow Googlers: You must pass in UITableViewDelegate in your class declaration to get .delegate to work!! For example, my class is called PickFavVC. This is what I have in PickFavVC.swift: class PickFavVC: UIViewController, UITableViewDataSource, UITableViewDelegate {
  • yes I disabled it first (by setting Selection to None in Storyboard) to focus on implementing the list with custom cells, once I started working on the navigation I forgot I had disabled it, took me a while to find the option highlighted in this answer..
  • Yup. I did the same. That's why i posted this answer :P
  • thanks , i forgot to change this selection.
  • add override as well