문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

Change tableView:didDeselectRowAtIndexPath into tableView:didSelectRowAtIndexPath.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top