2012-10-18 2 views
1

스토리 보드와 펜촉과 독립적으로 구성된 테이블 뷰에서 사용자 정의 셀을 사용하려고합니다.dequeueResusableCellWithIdentifier가 사용자 정의 셀을 반환하지 않습니다.

테이블 뷰의 큐 제거 메소드를 사용할 때마다 셀이 표준으로 돌아와 밀 셀을 실행합니다. 그러나 만약 내가 dequeuing을 사용하지 않는다면, 셀은 예상대로, 다시 말해, 커스터마이징됩니다. 다음은 작동하지 않는 부분입니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [self.tableView registerClass:[FloatingGradientCell class] forCellReuseIdentifier:@"Cell"]; 
    static NSString *CellIdentifier = @"Cell"; 
    FloatingGradientCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    if (cell == nil) 
     cell = [[FloatingGradientCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier topGradientColor:[UIColor blackColor] bottomGradientColor:[UIColor blackColor]]; 

    MWFeedItem *article = [_articles objectAtIndex:indexPath.row]; 
    cell.textLabel.text = article.title; 

    return cell; 
} 

이것은 작동합니다. . . .

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{  
    FloatingGradientCell *cell = [[FloatingGradientCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell" topGradientColor:[UIColor lightTextColor] bottomGradientColor:[UIColor whiteColor]]; 

    MWFeedItem *article = [_articles objectAtIndex:indexPath.row]; 
    cell.textLabel.text = article.title; 

    return cell; 
} 

정확하게 여기에 무슨 아이디어가 있습니까?

감사합니다.

+1

docs에서 : "지정된 식별자에 대해 클래스를 등록하고 새 셀을 만들어야하는 경우이 메서드는 initWithStyle : reuseIdentifier : 메서드를 호출하여 셀을 초기화합니다. nib 기반 셀의 경우이 메서드는 셀 제공된 nib 파일의 객체입니다. 기존 셀을 다시 사용할 수있는 경우이 메소드는 대신 셀의 prepareForReuse 메소드를 호출합니다. " . . . 그래서 어떻게 적절한 속성을 설정할 수 있습니다 ... –

+1

Storyboard 또는 Nib를 사용하지 않는다면 TableViewCell을 코드 ​​어딘가에 만들어야합니다. 또한,'dequeueReusableCellWithIdentifier :'는 사용자 정의 셀을'init' 할 것이고 (코드에 있다면'loadView'가 호출 될 것입니다). –

+0

나중에 내가 취한 경로는 loadView와 함께 사용자 지정 초기 화에서 사용한 코드를 구현하는 것이 었습니다. 그것은 작동하지 않는 것처럼 보이지만,로드하기 전에 셀에 두 가지 인수를 부여하는 데 도움이되지 않았습니다. . . –

답변

3

모든 셀에 대해 클래스를 다시 등록합니다. viewDidLoad와 같이 다른 위치에 사용자 정의 셀을 등록해야합니다.

+0

움직였습니다 ... 여전히 작동하지 않습니다. 그러나, 난 그냥 (셀 == nil) 결코 그래서 내 셀에 대한 이니셜 라이저를 호출 적이 결코 호출 된 가져올 것으로 나타났습니다 ... 내가 처음 셀을 초기화하는 방법으로 뭔가 놓치고 생각합니다. –

관련 문제