2011-05-10 4 views

답변

7

tableView:cellForRowAtIndexPath:에서 backgroundView 속성에 액세스하거나 설정해서는 안됩니다. 프레임 워크는 아직 인스턴스화하지 않았을 수도 있고, 발바닥으로 대체 할 수도 있습니다. 그룹화 된 일반 테이블 뷰는 이와 관련하여 다르게 동작하므로 새로운 미래 스타일이 될 수 있습니다.

배경 화면은 &/tableView:willDisplayCell:forRowAtIndexPath:으로 사용자 설정되어야합니다. 이 메소드는 처음 호출이 표시되기 직전에 호출됩니다. 원하는 경우 배경을 완전히 대체 할 수 있습니다. 나는 이런 식으로 일을한다.

-(void) tableView:(UITableView*)tableView 
    willDisplayCell:(UITableViewCell*)cell 
forRowAtIndexPath:(NSIndexPath*)indexPath; 
{ 
    static UIImage* bgImage = nil; 
    if (bgImage == nil) { 
     bgImage = [[UIImage imageNamed:@"myimage.png"] retain]; 
    } 
    cell.backgroundView = [[[UIImageView alloc] initWithImage:bgImage] autorelease]; 
} 
0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    [...] 
    UIImageView *bgImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgCellNormal.png"]]; 
    cell.backgroundView = bgImage; 
    bgImage release]; 
    [...] 
    return cell; 
} 
0

당신은 jQuery과 셀 클래스를 상속하여 셀의 배경 이미지를 설정하는 nib 파일을 사용할 수 있습니다. 그런 다음 셀을 재사용 당신이 정말로 메모리를 너무 많은 시간을 할당하지 않습니다에 대한 reuseIdentifier를 사용하는 경우

그렇지 않으면 당신은

UIImageView *imageView = [UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgCellNormal.png"]; 
cell. backgroundView = imageView; 
[imageView release]; 
2

하여 오토 릴리즈 개체를 제거 할 수 있습니다.

또한 png 파일이 프로젝트에 추가되면 [UIImage imageNamed : @ "bgCellNormal.png"를 대신 호출 할 수 있습니다.

UIImage imageNamed 함수는 최적화를 위해 이미지를 캐시합니다.

관련 문제