.
테이블보기 컨트롤러가 할당 해제 된 후 선택 사항을 유지하려면 선택한 항목을 NSUserDefaults
과 같은 곳에 저장해야합니다. synchronize
편집의 사용에
-(void)viewDidLoad
{
[super viewDidLoad];
NSArray *previousSelection = [[NSUserDefaults standardDefaults] objectForKey:@"selection"];
for (NSArray *selection in previousSelection) {
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:selection[1] inSection:selection[0]] animated:NO scrollPosition:UITableViewScrollPositionNone];
}
}
-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
NSArray *selections = [self.tableView indexPathsForSelectedRows];
NSMutableArray *selectionsToSave = [NSMutableArray array];
for (NSIndexPath *selection in selections) {
[selectionsToSave addObject:@[selection.section, selection.row]];
}
[[NSUserDefaults standardDefaults] setObject:selectionsToSave forKey:@"selection"];
// Save as iOS 7 now saves less frequently - see note
[[NSUserDefaults standardDefaults] synchronize];
}
참고 : 수정 답변 감사 만 NSUserDefaults
간단한 유형을 넣을 수 있다는 지적 @rmaddy합니다.
특정 셀의 인덱스 경로를 저장해야합니다. – limon