It looks like you're new here. If you want to get involved, click one of these buttons!
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *newCell =[tableView cellForRowAtIndexPath:indexPath];
int newRow = [indexPath row];
int oldRow = [lastIndexPath row];
if (newRow != oldRow)
{
newCell = [tableView cellForRowAtIndexPath:indexPath];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath: lastIndexPath];
oldCell.accessoryType = UITableViewCellAccessoryNone;
lastIndexPath = indexPath;
}
BusInfoAppDelegate *appDelegate =
(BusInfoAppDelegate *)[[UIApplication sharedApplication] delegate];
Station *arrivalStationPicked = [[sectionArray
objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
appDelegate.arrivalStationPicked =arrivalStationPicked;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Replies
Then I do something like this in cellForRowAtIndexPath:. In my case I'm putting a custom checked image on the left, but you can do the same thing with your checkmark accessory.
If there is a selection, figure out if this current item is the same as that selection, and respond accordingly. If there isn't a selection, show nothing.
Then I do almost the exact same thing in didSelectRowAtIndexPath:
Same basic idea. If the item is already selected, turn it off, if not turn it on, etc. Then the reload will take care of resetting the checked status of other items.
If you want to allow multiple selections, then do the same basic thing, but make your 'selection' property be an array. As items are de/selected, add/remove them to/from the array, then in cellForRow react depending on if your current object is in the selection array.
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI tried getting this work but it's not quite there. The problem I have is, when I select an item....it doesn't display the checkmark accessory item initially. But when you scroll a lot of items and return to what you selected, then the item is checked. Some how the reload data seems to be messing it up somehow.
I've tried following Brian's example but I'm think it works in that case since it appears to be a custom cell. This thing has been quite frustrating.
thanks
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeUpdate: I can only get this code to work if my cell is a custom cell. I tried using just a table view with normal/regular cells but the reload event/action always would wipe out the disclosure check. I'm not sure if earlier postings suggested that this code works best for custom table view cells. I'm glad I finally got passed this. It was really pissing me off for a while.
Thanks for posting the working code.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome