음, 기본적으로 싶은 것은 :
- 데이터 소스 (배열)에서 행을 삭제합니다.
- 데이터 원본에서 행을 삭제했음을 테이블보기에 알립니다.
올바른 코드는 아마과 같아야합니다
if (editingStyle == UITableViewCellEditingStyleDelete) {
[tableFavoritesData removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
편집 : 나는 다른 오류를 발견하지 않았다.
YES 또는 NO를 전달하는 것이 아니라 애니메이션의 유형을 지정해야합니다. 예 : UITableViewRowAnimationFade. 가능한 UITableViewRowAnimation 값 here을 확인하십시오.
편집 2 : 아래의 주석 (코멘트 형식화) : 문서에서 NSNotificationCenter을 확인하십시오. 특히 addObserver : selector : name : object : 및 postNotificationName : object : methods를 확인하십시오. 다른 뷰 컨트롤러에서
(아마의 viewDidLoad 방법) :
if (editingStyle == UITableViewCellEditingStyleDelete) {
...
[[NSNotificationServer defaultCenter] postNotificationName:@"RowDeleted" object:self userInfo:[NSDictionary dictionaryWithObject:indexPath forKey:@"IndexPath"]];
}
그냥 당신이를 할당 해제 때 알림 센터에서 관찰자를 제거해야한다는 것을 기억
[[NSNotificationServer defaultCenter] addObserver:self selector:@selector(deletedRow:) name:@"RowDeleted" object:nil];
-(void) deletedRow:(NSNotification*) notification
{
NSDictionary* userInfo = [notification userInfo];
NSIndexPath indexPath = [userInfo objectForKey:@"IndexPath"];
// your code here
}
및 행을 삭제하는 동안 다른 UIViewController :
[[NSNotificationServer defaultCenter] removeObserver: self];
희망 마 많은 오류가 발생했습니다. 저는 XCode atm에 액세스 할 수 없습니다.
대단히 감사합니다. (내 질문에 sidenote 다른 컨트롤러에서 테이블이있는 하나의 복사 된 데이터 배열이 있습니다. 전체 배열을 다시 복사 할 필요없이 그 배열에서 개체를 제거 할 수있는 방법이 있다면 다시 nsuserdefault if 제거 되었습니까?) –
답변에 샘플 코드를 추가 했으므로 이미 편집 된 내 의견을 편집 할 수 없습니다. 일반적으로 다른 ViewController를 옵저버로 등록하고 객체 삭제시 알림을 게시하려고합니다. – Mayjak