UITableView didSelectRowAtIndexPath never called

I have a UITableView inside a UIViewController that uses the UITableViewDelegate and UITableViewDataSource protocols. numberOfRowsInSection and cellForRowAtIndexPath .

There are outputs for the dataSource and delegate them to the storyboard. For TableView, the only choice is selected. Shows the selection when pressed.

I am running a project on a simulator, a table touch cell, received a call to didHighlightRowAtIndexPath , but didSelectRowAtIndexPath or willSelectRowAtIndexPath never called.

What did I forget? What can affect TableView in this way?

PS I know there are a lot of such questions, but I spent several hours searching on Google and read stackoverflow and still have not solved my problem.

TestViewController.h:

@interface TestViewController : ViewController <UITableViewDelegate, UITableViewDataSource>

@end

TestViewController.m:

 @interface TestViewController () @property (strong) IBOutlet UITableView *tableView; @end @implementation TestViewController - (void)viewDidLoad { [super viewDidLoad]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"selected"); } - (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"highlighted"); } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 10; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"FilterCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; cell.textLabel.text = @"some text"; return cell; } @end 
0
source share
2 answers

I have it. The problem was in the library that the project was using.

My ViewController was inherited from the implementation of the ViewController library, and it caught all the gestures.

+3
source

It's hard to say without seeing the code, but try the following:

1) didSelectRowAtIndexPath from UITableViewDelegate , NOT a dataSource , did you connect it ?!

2) Carefully check the didSelectRowAtIndexPath signature. Copy it to some reliable source. Maybe there’s some kind of dead end.

3) Make sure that the sockets are connected correctly. Stop it somewhere using the debugger, say viewDidLoad and print out the dataSource command and delegate ( po self.tableView.dataSource debugger), make sure they point to the correct object.

4) Is the row visually selected? Maybe you have cell.userInteractionEnabled set to NO in your code or storyboard?

5) The table view has a selection property in the storyboard: (Is everything all right?) enter image description here

6) Perhaps you have a table in edit mode? Write it from debugging to see.

7) Is a row indexPathsForSelectedRows from the point of view of the indexPathsForSelectedRows method? What if you redefine and register calls in the selected accessor cell?

+14
source

All Articles