UITableView does not select correctly

I am working on an iPhone application where I have a UITableView that is populated with an XML feed via a URL.

Say, for example, three cells are full.

If I click on the first cell, nothing happens, but if I touch the second or third cell, it takes me to the second screen connected with the cell, and the same thing happens with other cells - do not click on it, click on another, and it will lead me to the second screen of the previous selected.

I had never happened before and am rather confused.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"UITableViewCell"]; } cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; LocationsItem *atm = [[locations atms] objectAtIndex:[indexPath row]]; [[cell textLabel] setText:[atm atmName]]; float distance = [[atm atmDistance] floatValue]; NSString *distanceString = [NSString stringWithFormat:@"%0.2f miles from current location", distance]; [[cell detailTextLabel] setText:distanceString]; return cell; } - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; LocationsItem *atm = [[locations atms] objectAtIndex:[indexPath row]]; ATMDetailsController *detailsController = [[ATMDetailsController alloc] init]; [detailsController setCurrentATM: atm]; [[self navigationController] pushViewController:detailsController animated:YES]; } 

Thanks Nick

+4
source share
1 answer

You answered your question. The problem is that you used tableView:deselectRowAtIndexPath: instead of tableView:didSelectRowAtIndexPath:

It is noteworthy that this is due to the unfortunate fact that deselect precedes did in the dictionary, and therefore xcode usually awesome code terminates you!

Now to get those debugging hours back!

+9
source

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


All Articles