lilolme
lilolme

Reputation: 3

iOS simulator issue?

I am trying the Tutorial: Add Data from RoadMapiOS https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/index.html

The events don't seem to be fired in time. The first event is only called after three clicks. Then every event is one click behind. Sometimes it seems to be two behind.

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    NSLog(@"%d", (indexPath.row));
    XYZToDoItem *tappedItem = [self.toDoItems objectAtIndex:indexPath.row];
    tappedItem.completed = !tappedItem.completed;
    [tableView reloadRowsAtIndexPaths:@[indexPath]
                     withRowAnimation:UITableViewRowAnimationNone];
}

When I step through this with the debugger.

Click on        Console output
-------------------------------
Row 5           -
Row 3           4
Row 1           2
Row 3           0

The index is 0 based but seems to match the previous event. Is this just an issue with the simulator or could something be configured wrong?

Upvotes: 0

Views: 132

Answers (1)

ansible
ansible

Reputation: 3579

Looking at the link I think you have the wrong function. You have *de*selectRowAtIndexPath instead of *did*SelectRowAtIndexPath. This is why it's getting called "late" because it isn't called when you selected like expected, but when you select the next row, this fires for the previously selected row.

Try:

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

Upvotes: 1

Related Questions