Cambiar el tamaño de las celdas en mi proyecto

I have this table with custom cells, how cal cells be resizable according to the content?

- (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; 
} 

And here is the 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];
}

¡Gracias!

preguntado el 09 de marzo de 12 a las 13:03

1 Respuestas

After your cell content changed, reset cell height in - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath, y llama [cell setNeedsDisplay]; to draw cell again.

respondido 09 mar '12, 15:03

Ok, I've got this now: (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 65.0; - Icarox

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.