2010-05-05 9 views
0

NSFetchedResultsController가있는 코어 데이터 테이블에서 직접 데이터를로드하는 tableView가 있습니다. 반입 결과에서 객체를 저장하기 위해 중간 NSMutableArray를 사용하지 않습니다.테이블 뷰에 삽입 행 추가

기본적으로 내 UITableViewController 내에서 프로토콜 메서드 numberOfRowsInSection을 구현하고 NSFetchedResultsSectionInfo 내에 numberOfObjects를 반환합니다.

cell.textLabel.text = @"categoria"; 

I을 (합병증을 피하기 위해)를 fetchedResultController에서 객체 정보를 atIndexPath 및 검색하지만 지금 나는 어떤 객체에 대한 일반적인 구성이 :

id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section]; 

후 나는 configureCell를 구현하여 셀 내용을 구성 customSetEditing이라는 자체 선택기를로드하는 오른쪽에 사용자 정의 편집 버튼이있는 NavigationBar도 있습니다. 내가 달성하려고하는 것은 "셀 삽입"테이블 뷰의 시작 부분에로드하는 것이므로 탭하면 탭이 새로운 레코드를 만듭니다. 이 마지막 부분은 문제를 구현하기 쉽습니다. 탐색 막대를 편집 할 때 삽입 행이나 행을로드 할 수없는 것 같습니다.

- (void) customSetEditing { 
      [super setEditing:YES animated:YES]; 
      [self.tableView setEditing:YES animated:YES]; 
      [[self tableView] beginUpdates]; 
      //[[self tableView] beginUpdates]; 
      UIBarButtonItem *customDoneButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(customDone)]; 
      [self.navigationItem.rightBarButtonItem release]; 
      self.navigationItem.rightBarButtonItem = customDoneButtonItem; 
      //[categoriasArray insertObject:[NSNull null] atIndex:0]; 
      NSMutableArray *indexPaths = [[NSMutableArray alloc] initWithObjects:[NSIndexPath indexPathForRow:0 inSection:0],nil ]; 
      [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop]; 
      //[indexPaths release]; 
      [self.tableView reloadData];} 

를 추가하기 전에 :

내 customSetEditing 코드입니다 [self.tableView reloadData];를 나는 경계 부족 오류 플러스 프로그램이 다운 받고되었고 프로그램이 충돌하지 않지만 그것은 아무것도로드되지 않습니다.

나는 stackoverflow에서 비슷한 상황을 많이 보았습니다 (그런데 아주 유용한 도움을 주며 훌륭한 사람들과 훌륭한 토론장입니다). 아무도 예제가없는 것 같습니다.

아이디어가 있으십니까?

답변

0

당신은 그냥 응용 프로그램이이 방법에 주석 라인에 충돌하는 것을 발견 알고 : 나는 라인을 코멘트 경우 작동

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath { 
    //NSManagedObject *managedObject = [fetchedResultsController objectAtIndexPath:indexPath]; 
    cell.textLabel.text = @"categoria"; 
} 

.

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath { 
      if (![fetchedResultsController objectAtIndexPath:indexPath]) { 
       cell.textLabel.text = @"categoria"; 
      } 
      else{ 
       NSManagedObject *managedObject = [fetchedResultsController objectAtIndexPath:indexPath]; 
       cell.textLabel.text = @"categoria"; 
      } 

}

하지만 여전히 충돌 : 전혀 처음에 가져온 결과를 컨트롤러에 데이터가 없기 때문에 그것은있을 수 있습니다, 문제는 내가 함께 노력 그래서 내가 그 라인이 필요하다.

0

테이블이 비어있는 경우 -configureCell:atIndexPath:을 호출하면 안됩니다. -tableView:rowsInSection: 메소드는 어떻게 생겼습니까?

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section]; if (self.tableView.editing) { return ([sectionInfo numberOfObjects]+1); } return [sectionInfo numberOfObjects]; }

:
0

는 (I에 유래을 위해 그것을 해결하는 방법을 알아 냈 있지 않은 것 같습니다 혼란에 대해 죄송합니다) 코드입니다