Reputation: 571
I got the checkmarks appearing and disappearing correctly when scrolling and it works perfectly on simulator.
However on the device, a 4s, the touch to make the checkmark disappear again does not work properly. Meaning, I need to touch the row, which I want the checkmark to disappear twice. Only after the second touch the checkmark disappears.
Furthermore all selected columns remain with the blue background until I touch them again.
So here is the sequence (on the device):
What I definitely need, is that the checkmark disappears, as soon as I touch the row again, actually the behavior I am having on the simulator.
The background I guess I am able to control via the didDeselectRow method. However, I struggle with imagining, how to control the checkmark issue. Any ideas??
Here is the code from the didSelectRowAtIndexPath
:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger thisCardID;
NSInteger thisCardIndex;
NSString *cellValue;
UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
cellValue = thisCell.textLabel.text;
if(searching) {
thisCardID = [[self.aCopyOfCardIDArray objectAtIndex:indexPath.row] integerValue];
thisCardIndex = [self.aCopyOfCardIDArray indexOfObject:[NSNumber numberWithInteger:thisCardID]];
if (thisCell.accessoryType == UITableViewCellAccessoryNone) {
[self.searchedSelectedRowArray replaceObjectAtIndex:thisCardIndex withObject:@"YES"];
thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
[self.searchedSelectedCardIDs addObject:[NSNumber numberWithUnsignedInteger :thisCardID]];
}
else {
[self.searchedSelectedRowArray replaceObjectAtIndex:thisCardIndex withObject:@"NO"];
thisCell.accessoryType = UITableViewCellAccessoryNone;
[self.searchedSelectedCardIDs removeObject:[NSNumber numberWithUnsignedInteger:thisCardID]];
}
}
else {
thisCardIndex = [self.tempCardArray indexOfObject:cellValue];
if (thisCell.accessoryType == UITableViewCellAccessoryNone) {
[self.selectedRowArray replaceObjectAtIndex:thisCardIndex withObject:@"YES"];
thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
[self.selectedCardIDs addObject:[NSNumber numberWithUnsignedInteger :thisCardID]];
}
else {
[self.selectedRowArray replaceObjectAtIndex:thisCardIndex withObject:@"NO"];
thisCell.accessoryType = UITableViewCellAccessoryNone;
[self.selectedCardIDs removeObject:[NSNumber numberWithUnsignedInteger:thisCardID]];
}
}
}
To make sure I am making myself clear, I added some screenshots:
Upvotes: 1
Views: 401
Reputation: 571
Was to early to go to sleep and Heureka, it's the didDeselectRowAtIndexPath which does the magic. That's why the second touch is not recognized by the didSelect... method. Logical, if you know it :-) Now it's time to count sheeps...
Here the code:
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
thisCell.selectionStyle = UITableViewCellSelectionStyleNone;
thisCell.accessoryType = UITableViewCellAccessoryNone;
}
Upvotes: 2