2012-04-23 5 views
0

내 목표는 배경, 글꼴 및 크기와 함께 내 자신의 셀 스타일을 정의하는 것입니다. 나는 이것을 시험해 본다.TableView는 willDisplayCell에 입력하지 않습니다

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    ScreenListElements *currentScreenElement = [self.screenDefBuild.elementsToTableView objectAtIndex:indexPath.row]; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:currentScreenElement.objectName]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:currentScreenElement.objectName]; 

    } 

    cell.textLabel.text = currentScreenElement.objectName; 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
cell.contentView.backgroundColor = [UIColor blackColor]; 
} 

셀 backgrond를 변경하고 싶습니다. 그러나 앱이 willDisplayCell 메소드에 들어가지 않습니다. 수업을 다음과 같이 선언했습니다.

@interface MyTableView : UIViewController <UITableViewDataSource,NSCopying> { 
} 

내가 다른 것을 가지고 있어야합니까? 아니면 자신의 셀 스타일을 선언하는 더 좋은 방법 일 수도 있습니다.

+0

는 UITableViewDelegate'이 – Novarg

답변

5
@interface MyTableView : UIViewController <UITableViewDataSource, UITableViewDelegate ,NSCopying> { 
} 

있어서

tableView:willDisplayCell:forRowAtIndexPath 

는 방법을 위임이다 UITableView

EDITED

설정 대리인

,321 (그 정확한 & 허용 대답을 할) 0
+1

OK, 내가 대리자를 추가 할 수 있지만 여전히'잊지 마세요 아무것도 .. – Kuba

+0

ru 확실한가? coz 난 내 샘플 prog에서 그 라인을 추가 &보기의 배경이 색깔을 보여줍니다. UR 셀이 전혀 색이 나지 않거나 이상한 방식으로 색이 칠해져 있습니다. –

+1

@SimpleMan - 대리인을 설정해야합니다. myTableView.delegate = self – sosborn

0

"UITableViewDelegate"프로토콜을 구현하지 않았다는 것을 알았습니다. 데이터 소스 만 ... 따라서 위임 메서드는 반드시 입력하지 마십시오.

@interface MyTableView : UIViewController <UITableViewDataSource, UITableViewDelegate ,NSCopying> { 
} 
0

확인 UITableviewCell 위임 프로토콜 :

그것과 같이 있는지 확인

- (void)tableView:(UITableView *)tableView 
     willDisplayCell:(UITableViewCell *)cell 
     forRowAtIndexPath:(NSIndexPath *)indexPath{ 

    cell.contentView.backgroundColor = [UIColor blackColor]; 

}

관련 문제