0

I have a custom UITableView in a ViewController. My custom table has custom UITableViewCells. This is the code inside my ViewController:

ViewDidLoad:

        self.firstListTable.dataSource = self
        self.firstListTable.delegate = self
        self.firstListTable.register(UINib(nibName: "firstQueueCell", bundle: Bundle.main), forCellReuseIdentifier: "firstCell")

        self.searchListTable.dataSource = self
        self.searchListTable.delegate = self
        self.searchListTable.allowsSelection = true
        self.searchListTable.register(UINib(nibName: "SearchCell", bundle: Bundle.main), forCellReuseIdentifier: "SearchCell")
        self.searchListTable.separatorStyle = .none

UITableViewFunctions:

func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
    if tableView == self.searchListTable {
        print("hello") 
    }
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
   print("hello")
}

didHighlightRowAt works but didSelectRowAt does not.

I tried this: didSelectRowAtIndexPath: not being called

What other causes could there be?

Thanks!

Community
  • 1
  • 1
user82395214
  • 829
  • 14
  • 37
  • looks like there is no error in your code, can you post all the code about it let us have a look if is other place goes wrong? – aircraft Feb 19 '17 at 02:15
  • @user82395214, checked your code. Nothing wrong with it. Both of them are responding. Can you change `print` statement for `didSelectRowAt` method from `print("hello")` to something different and check it again? – KrishnaCA Feb 19 '17 at 03:52

1 Answers1

0

If you want didHighlightRowAt and didSelectRowAt both response, you can overwrite your method didHighlightRowAt like this :

func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
if tableView == self.searchListTable {
    print("hello") 

    // this is my OC code ,change it to your swift code 
    [tableView selectRowAtIndexPath:IndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];

    }
}

You can understand this as didHighlightRowAt method and didSelectRowAt method have conflicts, if you want both method response, you must make some special treatment.

aircraft
  • 25,146
  • 28
  • 91
  • 166
Mistrx丶
  • 267
  • 3
  • 10
  • Oh sorry, no I'm trying to say that my `didHighlight` works, but `didSelect` doesn't. I don't want the user to have to hold a cell to interact with it. – user82395214 Feb 19 '17 at 02:11
  • i know what you want, but if overwrite the both method like your code, `didSelectRowAt` is very hard to response. user must click very much time to call `didSelectRowAt`. – Mistrx丶 Feb 19 '17 at 02:17
  • can you tell me the real effort you want in `didHighlightRowAt`? i suggest you put the code for your effort in `didSelectRowAt` method. – Mistrx丶 Feb 19 '17 at 02:20