UITableView didSelectRowAtIndexPath: not working

When I select a table row, nothing happens. It did not hit the ContentController, and I cannot find the UILabel that was declared on ContentController.h when I want to associate it with resultLabel .

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { ContentController *detailview = [[ContentController alloc] initWithNibName:@"ContentController" bundle:nil]; detailview.detailString = [NSString stringWithFormat:@"%d",indexPath.row]; [self.navigationController pushViewController:detailview animated:YES]; [detailview release]; } 

Contentcontroller

 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. resultLabel.text = self.detailString; } 
+4
source share
11 answers

Perhaps this is due to the fact that you did not set the table view property for delegation and data source:

 tableview.delegate=self; tableview.datasource=self; 

or setting their property to xib is another option

+15
source

clickable == NO

There may be a state that is in the cellForRowAtIndexPath method:

 cell = [self tableCellWithHeight:height clickable:NO withArrowAccessory:NO]; 

if clickable == NO then the didSelectRowAtIndexPath method didSelectRowAtIndexPath never call this cell.

+3
source

Another thing to check is to make sure that the prototype cells and their selection mode or selection style.

Goto interface builder ->> utility windows on the right side -> attribute inspector -> look at the drop-down list.

In the Apple textbook I studied in, he asks you to set it equal, which makes it look like the delegate didSelect didn't shoot. By setting the selection mode to zero, this ability is effectively castrated. I changed this to Single Selection and it all started working again.

+2
source

Verifies that the control is inside didSelectRowAtIndexPath by applying a breakpoint. If not just check if you have a UITableView delegate installed or not.

0
source

in your ContentController.h

 NSString *detailString; @property (nonatomic, retain) detailString; 

ContentController.m

 @synthesize detailString; 

And in your class, where you have a table view. set table view delegate and datasource for themselves (in xib for file owner).

0
source

Here is the image of setting the data source and delegation in the interface builder for UITableview which is necessary for the method below for shooting at the touch.

..

  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.myAlphabet count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; cell.textLabel.text = [self.myAlphabet objectAtIndex:indexPath.row]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //method for getting text (can be changed to push views) NSString*mystring; mystring = [self.tableView cellForRowAtIndexPath:indexPath].textLabel.text; NSLog(@"%@",mystring); } 

Setting datasource and delegate in interface builder

0
source

When creating a cell (on cellForRowAtIndexPath), you should note:

UserInteractionEnabled property Determine whether the cell can be selected (when clicked, -didSelectRowAtIndexPath will call).

 if (!isClickable) { cell.userInteractionEnabled = NO; } 

selectionStyle property: Determine if the selected background view is selected by clicking.

 cell.selectionStyle = isClickable ? UITableViewCellSelectionStyleBlue : UITableViewCellSelectionStyleNone; 
0
source

Well, I had a different scenario, I have an HJManaged Image in a UITableView and HJManaged The image has its own tap method in its delegate , so when I click on the table view instead of didSelectRowAtIndexPath , the delegate delegate method is HJManaged Getting the image.

So, that I found a solution, I returned the UITableView Cell and the HJManaged Image enabled user interaction property is disabled.

0
source

Check if you are implementing this method

 - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath: (NSIndexPath *)indexPath { return NO; } 

disable cell selection

0
source

It may happen that you did not add the table view and data source delegate. Please make sure that these two lines in your view have been loaded.

  tableview.delegate=self; tableview.datasource=self; 
0
source

In my situation, I forgot to set the Delegate property of the View table. Perhaps you should connect the tableView delegate to the current controller.

0
source

Source: https://habr.com/ru/post/1381847/


All Articles