multitaskPro
multitaskPro

Reputation: 571

UITableView within a UIView not triggering didSelectRowAtIndexPath

I have been searching through the many SO answers for this question and have not found a solution that works, so I thought I'd ask one myself.

I have a normal UIViewController, and within in is a UITableView. I am populating the table view correctly, but the method

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath

is not being called. My data source and delegate have both been linked up correctly, I have User Interaction Enabled, and Single Selection is set for the Selection setting.

Could the issue be something with embedding a UITableView within a View Controller? How can I fix this?

Upvotes: 1

Views: 666

Answers (4)

multitaskPro
multitaskPro

Reputation: 571

So it turns out I was an idiot and put a line within my custom UITableViewCell that said

self.userInteractionEnabled = NO;

Oops :/

Thanks to everyone who tried to fix my issue.

Upvotes: 0

Ketan Parmar
Ketan Parmar

Reputation: 27428

Select your tableview from interface builder (i.e. from view controller or storyboard).

Then select attribute inspector from utilities,

Now make sure below settings are there,

 Selection - Single Selection

 Editing  - No Selection during editing (if you are selecting row during editing then change it)

 Show selection on touch checkbox should be checked

Under the view,

 User Interaction Enable must be Checked.

Then Select your tableview cell

And make sure,

 User interaction enable is checked under `view`

Then select content view of cell and check that user ineraction enable is checked.

Second thing make sure that user interaction is enable for your rootview (i.e. self.view) and whole view hierarchy comes between self.view and tableView.

And make sure that you have properly set datasource and delegate to self like,

  self.myTableView.delegate = self;
  self.myTableView.dataSource = self;

Upvotes: 0

hites
hites

Reputation: 159

have you set your tableview delegate and datasource ?

self.tableView.delegate = self;
self.tableview.dataSource = self;

Upvotes: 0

vivek tankariya
vivek tankariya

Reputation: 156

Have you used any gestureRecognizer? if yes then try this code.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ((touch.view == tblObj)) 
    {
        return NO;
    }
    return YES;
}

Upvotes: 3

Related Questions