2

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?

1
  • Please pay attention to message formatting (see the changes in your question) - each code line should begin with at least 4 spaces in order to look like a code (these spaces won't appear in the final post). Commented Aug 23, 2010 at 22:04

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

4 Comments

but why in apple exemple they do this: TimeZoneCell *timeZoneCell = (TimeZoneCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (timeZoneCell == nil) { timeZoneCell = [[[TimeZoneCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; timeZoneCell.frame = CGRectMake(0.0, 0.0, 320.0, ROW_HEIGHT); }
I'm not sure why they have done that. It's unnecessary code, and has no effect on the appearance of the cell. Go ahead and change ROW_HEIGHT to 500.0f, and you'll notice that nothing is any different. Remove the line altogether, still, nothing changes. The frame of the cell itself is sized by the table, always. You can only reliably change the frames of it's contents.
but how they do in the contact apps, we see a picture on the left and a tableview on the right, so there is two tablview in the view?
That is simply a custom table view cell. Have a look at this article. developer.apple.com/iphone/library/documentation/userexperience/…
1

If you want to change the height of the cell the implement the delegate method tableView:heightForRowAtIndexPath:.

If you want to change the width then you should only change it visually (set transparent background for all cell's subviews except the ones that shouldn't be) or, if all the cells should have the same width, you might change the entire table view's width, as @Jerry Jones has advised...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.