그래서 model이라는 사용자 정의 NSObject 클래스가 있습니다. 내 문제는 내 배열 및 nsuserdefaults에서 사용할 수 있도록 이미 보관 된 이러한 사용자 지정 모델 개체의 배열이 있다는 것입니다. 나는 그들을 파기하는 방법에 붙어있다. 내 보관 방법은 보관 방법을 호출하고 결과를 nsuserdefaults의 배열에 저장하는 별도의 메소드가 있으므로 작동합니다. 개별 모델 객체를 보관하기 위해 잘 작동하는 메소드가 있지만 배열의 모든 아카이브 된 오브젝트를 보관 취소하는 방법을 알아야합니다.목표 C 사용자 정의 nsobjects의 보관 불가능한 배열
보관 방법 :
- (void)writeFavoriteObject:(Model *)favorite
{
NSData *favoriteObject = [NSKeyedArchiver archivedDataWithRootObject:favorite];
[[NSUserDefaults standardUserDefaults] setObject:favoriteObject forKey:kNSUSERDEFAULTSCAR];
[[NSUserDefaults standardUserDefaults] synchronize];
}
보관 취소 방법 : 보관 해제 내 배열을 사용하는
- (Model *)readFavoriteObjectWithKey:(NSString *)key
{
NSData *favoriteobject = [[NSUserDefaults standardUserDefaults]objectForKey:key];
Model *favorite = [NSKeyedUnarchiver unarchiveObjectWithData:favoriteobject];
return favorite;
}
내 시도 :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"NewsCell";
CarViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
defaultsarray = [[NSMutableArray alloc]init];
defaultsarray = [defaults objectForKey:@"favoritesarray"];
FavoriteCar = [defaultsarray objectAtIndex:indexPath.row];
FavoriteCar = [self readFavoriteObjectWithKey:kNSUSERDEFAULTSCAR];
cell.CarName.text = FavoriteCar.CarModel;
cell.CarImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:FavoriteCar.CarImageURL relativeToURL:[NSURL URLWithString:@"http://pl0x.net/image.php"]]]];
//Accessory
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.layer.borderWidth=1.0f;
cell.layer.borderColor=[UIColor blackColor].CGColor;
cell.CarName.layer.borderWidth=1.0f;
cell.CarName.layer.borderColor=[UIColor whiteColor].CGColor;
return cell;
}
내있는 tableview 행의 정확한 수를 표시 I 때문에 정확한 수를 얻을 수 있지만 셀은 첫 번째 Object를 반복합니다. 가능한 솔루션은 [FavoriteCar readFavoriteObjectWithKey:kNSUERDEFAULTSCAR];
과 같은 일종의 방법이 될 수 있으므로 각 객체는 아카이브되지 않습니다. 어떤 도움을 주시면 감사하겠습니다!
cellForRowAtIndexPath' '의 모든 시간을 보관 해제하는 것은 매우 비효율적이다 - 당신은 viewDidLoad''와 같은 방법으로 보관 해제해야합니다. 그런 다음 중단 점을 설정하고 배열의 데이터를 검사 할 수 있습니다. – Paulw11
감사합니다. 좋은 아이디어 – Chris