1
NSUserDefaults에서 읽은 mutablearray로 채워진 UITableView가 있습니다. 사용자가 현재있는 항목 중 일부를 제거 할 수 있기를 바랍니다. 다음은 여기에 편집 방법에 대한 구체적이고 코드는 전체 파일입니다 : http://pastebin.com/LmZMWBN9UITableView 커밋 편집 오류
것은 내가 "편집"버튼을 클릭 항목을 응용 프로그램이 충돌을 제거하고 난 다시 얻을 :
응용 프로그램을 종료로 인해 캐치되지 않는에 예외 'NSInternalInconsistencyException', 이유는 : '- [__ NSCFArray removeObjectAtIndex :] : 방법은 불변의 객체로 전송 돌연변이'
는
내 특정 질문에, 내가 잘못 여기서 뭐하는하고 있습니까?
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// edit list of names
if ([listOfNames count] >= 1) {
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[listOfNames removeObjectAtIndex:[indexPath row]];
// write updated listofnames to nsuserdefaults
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[[NSUserDefaults standardUserDefaults] setObject:listOfNames forKey:@"My Key"];
[defaults synchronize];
if ([listOfNames count] == 0) {
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
[tableView endUpdates];
}
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
가, 파일의 잘못된 버전을 라이브 프로젝트에 다시 복사/붙여 넣기했습니다. 나는 계속 말했습니다. "나는 내가 그것을 바꿨다는 것을 안다.".. 감사합니다. @ 그래버. 그것이 가능할 때 이것을 정확하게 선택할 것입니다. – TerryG