2011-09-14 4 views
0

내 앱에 UITableView가 있습니다. 이 코드를 아래에 넣을 때까지 모든 것이 올바르게 작동합니다.tableview를 건드릴 때까지 UITableView 배경이 나타나지 않습니다 - 또한 glitchy

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

//이 문제를 일으키는 코드입니다.

UIView *blackBGView = [[UIView alloc] init]; 
    blackBGView.backgroundColor = [UIColor blackColor]; 
    cell.backgroundView = blackBGView; 

어디서나 uitableview를 클릭 할 때까지 배경이 나타나지 않는 것이 문제입니다. 그 다음에는 일부 시간에만 작동합니다. 배경 화면은 정말 이상합니다.

내가 뭘 잘못하고 있니?

답변

1

blackBGView 헤더에 정의 다음 viewDidLoad에 다음 코드를 호출

blackBGView = [[UIView alloc] init]; 
blackBGView.backgroundColor = [UIColor blackColor]; 

을 다음 cellForRowAtIndexPath: 당신이 호출 할 수 있습니다

cell.backgroundView = blackBGView; 

을 그러나, 나는 확실하지 않다 이유를 셀로 UIView를 추가하면 다음과 같이 호출 할 수 있습니다.

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