user1118019
user1118019

Reputation: 3969

iOS tableviewcell width not same as tableview

I am creating a custom tableviewcell, so i believe by default tableviewcell width will be as wide as tableview itself right?

So after tableview is created, I did:

NSLog(@"%f",self.view.frame.size.width);

... which returns 476.00, and when I am instantiating my custom tableviewcell it is returning 320 instead...

NSLog(@"%f", self.frame.size.width);

I want the value of 476 when or after creating the cell... Because I am using it as a guideline to see how many columns I should have...

So, how can I obtain the full cell width?? (btw, the cell does take the entire row, after I print the background as yellow)

Upvotes: 2

Views: 1634

Answers (3)

Aniket K.
Aniket K.

Reputation: 144

Check for this:

-(void)layoutSubviews
{
    // Set the UITableView frame here:
    [super layoutSubviews];
}

Upvotes: 1

rdelmar
rdelmar

Reputation: 104082

I've set up an iPhone app to start in landscape mode, and log the table width and cell width, and I get the same thing you see (until I scroll the table, and then it changes the value to the correct wide value). Unless you're subclassing setFrame: in your custom cell, the cell width will be the same as the table width, so why not just use the self.view.frame.size.width (of your view) in your calculations?

Upvotes: 0

ZTB
ZTB

Reputation: 1

guestTable =  [[UITableView alloc] initWithFrame:CGRectMake(0,74,320,340)      style:UITableViewStyleGrouped];

So in the CGRectMake it defines the UITableView. Is this what you meant? It should autoset the cells to the UITableView width.

Upvotes: 0

Related Questions