Hello,
I have an app with a UITableView, using both icons and disclosure buttons. I want to update the icon on a row with a "selected" icon, and update the previously-selected row with an "unselected" icon. I have the code in place, but when I click on the rows, it sets both rows to the "selected" state, even though via debugging I can see that my state variable is being set to the correct row. If I keep clicking rows I can sometimes get the "unselected" state to show. I suspect it's a refresh issue, but I've tried the setNeedsDisplay method on the cells and the tableView itself, but with no luck. Anyone run into this before? BTW, this is in the simulator (2.2.1) - haven't tried it on the device.
Here's the code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int newRow = [indexPath row];
int oldRow = [lastIndexPath row];
if (newRow != oldRow)
{
[[tableView cellForRowAtIndexPath:indexPath] setImage: [UIImage imageNamed:@"IsSelected.png"]];
c_oListPtr.c_sCurItem = [[tableView cellForRowAtIndexPath:indexPath] text];
[[tableView cellForRowAtIndexPath:lastIndexPath] setImage: [UIImage imageNamed:@"NotSelected.png"]];
[lastIndexPath release];
lastIndexPath = indexPath;
[[tableView cellForRowAtIndexPath:lastIndexPath] setNeedsDisplay];
[[tableView cellForRowAtIndexPath:indexPath] setNeedsDisplay];
[tableView setNeedsDisplay];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Thanks -Mike
-
Have you tried
[tableView reloadData]
? -
Well, that did it. Thanks for the tip, though, if I may say, does it seem extraordinary that I have to reload all of the data (at least what's visible) to get this to work?
Oh well, nothing succeeds like success. Thanks again for the help!
-Mike
0 comments:
Post a Comment