Reputation: 479
I implemented the UITableView in my iPhone application. Further more I added multiple selection of row in UITableView.But the problem is that when I select particular row and then scrolls table and come back then respective row in unselected(unmarked).Here is my didSelectRowAtIndexPath method.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if([tableView cellForRowAtIndexPath:indexPath].accessoryType==UITableViewCellAccessoryNone)
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType=UITableViewCellAccessoryCheckmark;
[selectedIndexes addObject:[NSNumber numberWithInt:indexPath.row]];
NSLog(@"Select now %d",[selectedIndexes count]);
}
else if([tableView cellForRowAtIndexPath:indexPath].accessoryType==UITableViewCellAccessoryCheckmark)
{
[tableView cellForRowAtIndexPath:in dexPath].accessoryType=UITableViewCellAccessoryNone;
[selectedIndexes removeObject:[NSNumber numberWithInt:indexPath.row]];
NSLog(@"DeSelect now %d",[selectedIndexes count]);
}
}
Please provide me solution.
Upvotes: 0
Views: 713
Reputation: 221
While you are scrolling the table view every time,the delegate method cellForRowAtIndexPath method is called every time..So,it will load the data every time.Means, first you have to store which rows are clicked in didSelectRowAtIndexPath method, and according to these rows indexes in cellForRowAtIndexPath method you have to show that which table view rows are already selected with check marks and for remaining rows with out check mark...
Upvotes: 1
Reputation: 4733
check this. multiple-row-selection-and-editing
You will find really easy & usefull.
Enjoy Programming
Upvotes: 0