題名の通り、NSUserDefaultsにNSIndexPath型の値を入れた時の取り出し方法がわかりません。
最終的にやりたいことは、選択したセルをUserDefaultsに保存して、
次に開く時に、選択された状態にしたいです。(いわゆるチェックマーク的なもの...。)
iOS12
Objective-C
Xcode10
ObjectiveC
1// セルが選択された時に呼び出される 2- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 3 // 選択されたセルを取得 4 UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 5 // セルのアクセサリにチェックマークを指定 6 cell.accessoryType = UITableViewCellAccessoryCheckmark; 7 [cell setSelected:NO animated:YES]; 8 9 //インスタンスを生成 10 NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults]; 11 //選択したセルを保存 12 [userDef setObject:indexPath forKey:@"selectedCell"]; 13 //同期 14 [userDef synchronize]; 15}
ObjectiveC
1//画面が変わった時 2-(void)viewWillAppear:(BOOL)animated{ 3 // ナビゲーションバー表示 4 [self.navigationController setNavigationBarHidden:NO animated:YES]; 5 6 //インスタンスを生成 7 NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults]; 8 9 //indexPathの値を取得 10 NSData *indexPath = [userDef objectForKey:@"selectedCell"]; 11 12 NSIndexPath *idxPath; //ここでうまくNSDataをNSIndexPathに変換させたかった...。 13 14 // 選択されたセルを取得 15 UITableViewCell *cell = [_soundTable cellForRowAtIndexPath:idxPath]; 16 // セルのアクセサリにチェックマークを指定 17 cell.accessoryType = UITableViewCellAccessoryCheckmark; 18}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/17 12:43