0

I have a UITableView inside a UIViewController that adopts UITableViewDelegate & UITableViewDataSource protocols. numberOfRowsInSection and cellForRowAtIndexPath are implemented.

There are outlets for dataSource & delegate in storyboard. Single selection is chosen for TableView. Show selection on touch is checked.

I run project on the simulator, touch table cell, got didHighlightRowAtIndexPath call, but didSelectRowAtIndexPath or willSelectRowAtIndexPath are never called.

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

P.S. I know, there is a plenty of questions like this, but I've spent a few hours googling and reading stackoverflow and still didn't solve 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 
3
  • don't you think it would be helpful to add your code? or do you expect us to have mind reader capabilities? Commented Nov 16, 2013 at 15:47
  • @vikingosegundo I'll add it, but there is nothing special. I've even changed my class to a simple one just for testing Commented Nov 16, 2013 at 16:13
  • @Serhii Yakovenko, it's ViewController inherited from STableViewController (for "load more" implementation). Bad name, I know Commented Nov 16, 2013 at 16:29

2 Answers 2

14

Hard to say without seeing code, but try this:

1) The didSelectRowAtIndexPath is from UITableViewDelegate, NOT dataSource, do you have it connected?!

2) Check the signature of didSelectRowAtIndexPath carefully. Copy paste it from some trusted source. Maybe some mistype there.

3) Be sure that outlets are connected properly. Stop it somewhere with a debugger, say viewDidLoad and print dataSource & delegate (po self.tableView.dataSource debugger command), make sure they point to the correct object.

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

5) Table view has a selection property in storyboard: (Is it ok?) enter image description here

6) Maybe you have table in editing mode? Log it from debug to see.

7) Does the row get's selected from point of view of indexPathsForSelectedRows method? What if you override and log calls to cell's selected accessor?

Sign up to request clarification or add additional context in comments.

6 Comments

1) Yes, both are connected (delegate & dataSource). didHighlightRowAtIndexPath is called. 2) copied from ios docs (just in case). 3) logged both connections, they're ok
I see visual effects and logs of cell highlight; cell's userInteractionEnabled is checked and I don't change it in code; single selection for tableview is set.
6) in didHighlight tableView.editing is NO; and even changing to 'single selection in editing mode' didn't help. 7) I'm checking it also in didHighlight and it's always null
wow, I've got a selected cell by long tap on it (really long and really unnatural) and now I can't select any other cell. Also I've notices that changing cell's selection style to blue (from gray) in storyboard or code doesn't really change it.
the problem was in a library used there, but still many thanks for your help!
|
3

I've got it. Problem was in a library that project uses.

My ViewController was inherited from a library's ViewController implementation and it was catching all the gestures.

4 Comments

Please explain further to help others and then select this is the answer.
This got me everytime, Check your gesture recognizer, if you add gesture recognizer to table view, the didSelectRowAtIndexPath will not running.
This got me more than once too @EdwardAnthony. I managed to solve it by not cancelling touches in view. UITapGestureRecognizer *tapRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]; [tapRec setCancelsTouchesInView:NO];
Forest, you're a Goddamn genius!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.