Objective-c – change width of a uitableviewcell

iphoneobjective cuitableview

I try to change the with of a cell in a tableview, I don't do a custom cell, I just subclass uitableviewcell.

This is the class

@implementation customCell

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

    if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {

        CGRect nouveauframe = CGRectMake(0.0, 0.0, 44,44);

        self.frame = nouveauframe;

    }
    return self;
}

-(void)dealloc
{

    [super dealloc];
}

@end

and this is when I create my cell in the cellForRowAtIndexPath:

static NSString *CellIdentifier = @"customCell";

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

if (cell == nil) {
    cell = [[[customCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell...

[[cell textLabel]setText:[[[[Mission singletonMission] getObjectDataHistoireEncours] objectAtIndex:indexPath.row] valueForKey:[[langue singletonLangue] valeurBalise: @"_nom_label"]]];

cell.detailTextLabel.text = [[[[Mission singletonMission] getObjectDataHistoireEncours] objectAtIndex:indexPath.row] valueForKey:[[langue singletonLangue] valeurBalise: @"_valeur"]];

cell.userInteractionEnabled = FALSE;

retour = [cell retain];

but the width of my cell don't change, why?

Best Answer

Table views change the frame of cells when they are added to the table view. If you want to change the width of a cell, you should either change the width of the table, or change the width of the contentView in the cell.

Related Topic