2014-10-12 4 views
1

내 프로젝트에서는 테이블 뷰와 셀 같은 코드로 모든 것을 만듭니다. 나는 세포를 추가하는 기능이있다. 상황 : 내 배열에 10 개의 객체가 있습니다. 프로그램이 실행될 때 (- (TodoTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath) 함수는 스크롤 할 때 10 개의 셀을 모두 실행합니다. 셀 클래스에서 10 번 실행됩니다. 그러나 프로그램에 새 셀을 추가하면이 새 셀이 어떤 이유로 init 함수를 호출하지 않는다는 것을 알게되었습니다.IOS-TableView 셀 : dequeueReusableCellWithIdentifier 문제

내가 추가하려면이 부분을 사용 (셀이 성공적으로 ...하지만 이상한 생성되는) 세포 :

[self.tableView beginUpdates]; 
    [self.todoItemList insertObject:newItem atIndex:toBeAddedIndex]; 
    [self.tableView insertSections: [NSIndexSet indexSetWithIndex:toBeAddedIndex] withRowAnimation:UITableViewRowAnimationNone]; 
    [self.tableView endUpdates]; 

이 기능에

는 :

- (TodoTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
NSLog(@"Scroll to %ld", indexPath.section); 
static NSString *cellIdentifier = @"TodoCell"; 

TodoTableViewCell *cell = (TodoTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; 

//If the current cell is dummycell, make it transparent 
cell.todoItem = (TodoItem *)(self.todoItemList[indexPath.section]); 

난 이유를 모르겠어 누구나 친절 -----------------

---------- UPDATE 도와주세요

NSString *cellIdentifier = [NSString stringWithFormat:@"TodoCell%ld",indexPath.section]; 
,

이 행으로 변경하면 발견했습니다. 새 셀을 추가 할 때마다 init 함수가 호출됩니다. 하지만 ... 내가 먼저 삭제 한 다음 추가 할 때,이 식별자가 생성되어 사용되고 저장 되었기 때문에 여전히 거기에 문제가있는 것 같습니다.

답변

1

호출하려고 :

[self.tableView insertRowsAtIndexPaths:<#(NSArray *)#> withRowAnimation:<#(UITableViewRowAnimation)#>] 
+0

문제는 내가 셀 사이의 간격을 필요로하기 때문에 내가 대신 행 섹션을 사용한다는 것입니다. 그래서 함수 : heightForHeaderInSection이 나에게 도움이된다. – Colafroth

+0

나는 시도했다 : [self.tableView insertSections : [NSIndexSet indexSetWithIndex : toBeAddedIndex] withRowAnimation : UITableViewRowAnimationNone]; \t \t [self.tableView insertRowsAtIndexPaths : @ [[NSIndexPath indexPathForRow : 0 inSection : toBeAddedIndex]] withRowAnimation : UITableViewRowAnimationNone]; 새로운 생성 된 셀의 init 함수가 여전히 호출되지 않습니다. – Colafroth

+0

당신은 어느 전화를하고 있습니까? 당신이 전화해야한다고 생각합니다 - (instancetype) initWithStyle : (UITableViewCellStyle) 스타일 reuseIdentifier : (NSString *) reuseIdentifier –

관련 문제