Frage

When I use

tableView:didSelectRowAtIndexPath / popViewControllerAnimated

it does not work. I push the view controller by another view but when I select a row, it highlights in gray instead of immediately popping to the original view controller. But when I tap another row, it selects the first row I tapped and then goes back to the original view controller.

Here is the code:

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    cell.accessoryType = UITableViewCellAccessoryCheckmark;

    NSArray *allTypes = [[ItemStore sharedStore] allTypes];
    NSManagedObject *raum = allTypes[indexPath.row];
    self.an.leben = raum;

    [self.navigationController popViewControllerAnimated:YES];
}

Any ideas?

War es hilfreich?

Lösung

Replacde didDeselectRowAtIndexPath with didSelectRowAtIndexPath.

The delegate method you have written is didDeselectRowAtIndexPath instead of didSelectRowAtIndexPath. According to apple, tableView:didDeselectRowAtIndexPath: Tells the delegate that the specified row is now deselected.

and

tableView:didSelectRowAtIndexPath: Tells the delegate that the specified row is now selected.

So, what is happening is, when you click on a row, it becomes selected and turns gray and then when you click on the same or any other row, the previous one gets deselected because only one row is selected at once and hence calls this method to open the next view controller with the previous tapped row.

Andere Tipps

Change tableView:didDeselectRowAtIndexPath into tableView:didSelectRowAtIndexPath.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top