2012-07-27 5 views
0

이 질문은 cellForRowAtIndexPath에 대한 것입니다.cellForRowAtIndexPath : XCode 템플릿이 맞습니까?

나는 올바른 방법이

UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 
if (cell == nil) { 
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"Cell"]; 
return cell; 

알고하지만 마스터 - 상세 템플릿을 만들 때, 코드는 다음과

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 
[self configureCell:cell atIndexPath:indexPath]; 
return cell; 
} 

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath 
{ 
NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath]; 
cell.textLabel.text = [[object valueForKey:@"timeStamp"] description]; 
} 

편집처럼 보이는 : 문제는 configureCell atIndexPath에 대해 없습니다. XCode 템플릿에는 이러한 문자열이 없습니다.

if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:cellIdentifier] ; 

XCode 템플릿이 맞습니까?

+0

이것을 확인하면 답변을 얻을 수 있습니다. http://stackoverflow.com/questions/5467831/why-do-programmers-use-configurecellatindexpath-method-to-config-the-tableview – Dhruv

답변

4

템플릿 코드가 정확합니다.

iOS 5.0부터는 셀 식별자에 펜촉을 등록 할 수 있습니다. 테이블에 셀이 필요하고 재사용 가능한 셀이 없으면 항상 펜촉을 인스턴스화하여 셀을 만듭니다.

이렇게하면 dequeueReusableCellWithIdentifier:은 항상 셀을 반환합니다. 당신 스스로 그것을 만들 필요가 없습니다.

닙을 등록하는 API는 registerNib:forCellReuseIdentifier:입니다.

관련 문제