tableView:cellForRowAtIndexPath: not working correctly when testing on iphone
-
27-10-2019 - |
سؤال
Currently i have a uitableview that the user can scroll through and select a cell. When the cell has been selected I save that indexpath value and when the user comes back to the view with the uitableview in it I pass that indexpath value back and assing a tick to that cell inside tableView:cellForRowAtIndexPath: using the code below.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//...
//Replaces previously selected cells accessory view (tick)
if (indexPath == oldCheckedData)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
NSLog(@" Tick");
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
NSLog(@"No Tick");
}
}
the weird thing being is that when testing this on the emulator it works perfectly.... However when I try to test it on the phone it never enters the first if statement... so the tick is never added.
المحلول
I think you are comparing pointers, not the index path. Instead of equal equal, use:
[indexPath isEqual:oldCheckedData]
لا تنتمي إلى StackOverflow