2011-08-21 3 views
0

크기 (높이)가 다른 사용자 정의 셀이있는 테이블을 만들어야합니다. 하나 또는 두 개의 셀에서 행의 크기를 변경할 수 있습니까 ?? 어떤 아이디어?다른 행과 다른 행의 크기

감사

답변

2

모든 행의 높이를 포함하는 가변 배열을 만들 수 있습니다. 여러 섹션이있는 경우 가변 배열에 여러 배열을 넣을 수 있습니다. 테이블 뷰 컨트롤러,

- (NSMutableArray *)heightData 
{ 
    if(nil == heightData) 
    { 
     heightData = [[NSMutableArray array] retain]; 

     //various heights for your different rows in different sections: 
     NSMutableArray *sectionArray1 = [NSMutableArray arrayWithObjects:[NSNumber numberWithFloat:44],[NSNumber numberWithFloat:44]]; 
     NSMutableArray *sectionArray2 = [NSMutableArray arrayWithObjects:[NSNumber numberWithFloat:44],[NSNumber numberWithFloat:44]]; 

     [heightData addObject:sectionArray1]; 
     [heightData addObject:sectionArray2]; 
    } 

    return heightData; 
} 

다음 다음하는 .m 파일에

@property (nonatomic, retain) NSMutableArray *heightData; 

:의 당신이이 개 섹션과 각 2 개 행을 가지고 가정 해 봅시다, 다음 테이블 뷰 컨트롤러 속성을 제공 하는 .m 파일이처럼 구현할 수 있습니다, 우리가 사용할 수 있도록해야합니다 프로토콜 방법이있다 :

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSMutableArray *rowArray = [self.heightData objectAtIndex:indexPath.section]; 
    NSNumber *height = [rowArray objectAtIndex:indexPath.row]; 
    return [height floatValue]; 
} 

마지막 단계 : 당신이 행의 높이를 변경하고자 할 때,의 그것의 행입니다 가정 해 봅시다 섹션 1, 행 0, th 당신은이 작업을 수행 할 수 있습니다 도중 :

NSMutableArray *rowArray = [self.heightData objectAtIndex:1]; 
[rowArray replaceObjectAtIndex:0 withObject:[NSNumber numberWithFloat:55]];\\a new data 
[self.tableView beginUpdates]; 
[self.tableView endUpdates]; 

다음 테이블 뷰의 부드러운 애니메이션 행의 크기를 조정하는 것, 당신은 명시 적으로 크기를 조정하고 행 내부의 뷰를 레이아웃 다시,하지만 난 그렇게하지 않는 것이 좋습니다 수 있으며, 사용자 정의 -xib 셀이 있고 자동 크기 조정 설정이 제대로 설정된 경우 테이블보기가 자동으로이 작업을 수행합니다.

+0

감사합니다. 그게 내가 필요한거야! 감사!!! – DaSilva

관련 문제