2012-03-09 6 views
0

이 셀에는 사용자 정의 셀이 있으며, 내용에 따라 cal 셀의 크기를 조정하는 방법은 무엇입니까?내 프로젝트의 셀 크기 조정

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"CustomTableCell"; 
    static NSString *CellNib = @"DetailViewCell"; 


    DetailViewCell *cell = (DetailViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil]; 
     cell = (DetailViewCell *)[nib objectAtIndex:0]; 
    } 

    cell.accessoryType = UITableViewCellAccessoryNone; 
    cell.cellTitleLabel.textColor = [UIColor blackColor]; 
    cell.cellSubtitleLabel.textColor = [UIColor darkGrayColor]; 

    informations = [[NSArray alloc] initWithObjects:titleString, subtitleString, stateString, categoryString, populationString, nil]; 
    subtitles = [[NSArray alloc] initWithObjects:@"City", @"Country", @"State", @"Category", @"Population", nil]; 

    cell.cellTitleLabel.text = [informations objectAtIndex:indexPath.row]; 
    cell.cellSubtitleLabel.text = [subtitles objectAtIndex:indexPath.row]; 

    return (DetailViewCell *) cell; 
} 

그리고 여기가 DetailViewCell.m

#import "DetailViewCell.h" 

@implementation DetailViewCell 

@synthesize cellTitleLabel; 
@synthesize cellSubtitleLabel; 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     // Initialization code. 
    } 
    return self; 
} 

- (void)dealloc { 
    [cellTitleLabel release]; 
    [cellSubtitleLabel release]; 
    [super dealloc]; 
} 

감사합니다!

답변

0

셀 내용이 변경된 후에 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath에 셀 높이를 다시 설정하고 [cell setNeedsDisplay];을 호출하여 셀을 다시 그리십시오.

+0

좋아, 지금이있어 : (CGFloat) tableView : (UITableView *) tableView heightForRowAtIndexPath : (NSIndexPath *) indexPath { return 65.0; – Icarox

+0

감사합니다 fannheyhard, 그것은 진짜로 나를 hepled;) – Icarox

관련 문제