I am Newbie in iOS Development. I want to make an Application that Contain UITableview. I want to Show when user Select UITableView Cell then it Like as Check marked it is Worked as i want but now i want to Show when User Back to Other View And Come back to Table View then it Shows Your Past Selection Of Table View Cell Please Give me Solution For that.
I Show in Stack Overflow it is Done by NSUSerdefault i find a code for it and Set like as But it is Not Working for me Please Give me Solution.
Here my UITableview didSelectRowAtIndexPath Method.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CategoryCustumCell *cell = (CategoryCustumCell *)[tableView cellForRowAtIndexPath:indexPath];
NSString *selectedCell= cell.categoryLabel.text;
NSLog(@"Category label %@",selectedCell);
NSString *text=[self.categoryArray objectAtIndex:indexPath.section];
if([self isRowSelectedOnTableView:tableView atIndexPath:indexPath])
{
[self.selectedCells removeObject:indexPath];
[self.selecedStates removeObject:text];
cell.accessoryType = UITableViewCellAccessoryNone;
} else
{
[self.selectedCells addObject:indexPath];
[self.selecedStates addObject:text];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
NSLog(@"%@", self.selecedStates);
NSUserDefaults *userdefaults = [NSUserDefaults standardUserDefaults];
[userdefaults setObject:[NSString stringWithFormat:@"%d",indexPath.section] forKey:@"lastIndexPathUsed"];
[userdefaults synchronize];
}
And I write to Fetch NSUserdefault Data in viewDidLoad like as
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
self.lastIndexPath = [defaults objectForKey:@"lastIndexPathUsed"];
and i Define in my .h file
@property (nonatomic,retain) NSIndexPath *lastIndexPath;
But i not Get Selection on User Come Back to the View Please Give me Solution for it.
Aucun commentaire:
Enregistrer un commentaire