Width of grouped UITableViewCell

I am working on some iPhone development at the moment. I have built a cell for a UITableView in Interface Builder. The cell was a bit too wide for the cell in my table view, and I realised it was because the cell in the NIB is full width but I am loading it into a grouped table view.

I didn’t want to have to measure it myself so I searched for the width. Couldn’t find it. So I measured it myself. And put it here. So maybe I will start getting a few more visits to this page from now on!

The magic number is…

300

The width of a grouped UITableViewCell is 300 pixels.

15 thoughts on “Width of grouped UITableViewCell

  1. Thanks! A google search brought me straight here for the magic number I needed! If you had an ad on this post i would have given it a click :)

    Brad

  2. The magic number seems to be 20. Each margin is 10. So when you rotate you can use these fixed values.

    Also, the following seems to work for me without using the constants:

    self.contentView.bounds.size.width

  3. While a very useful number, this is only the magic number for iphone.

    It is different for the iPad… which seems to have a % width based on the overall size of the table. Something I have yet been able to determine effectively. :(

    • You are correct, sir. At least about it being iPhone only. I haven’t had the need to use a grouped table view on the iPad so far. I am still surprised there is no way to get that value programatically. I think from memory even the frame/bounds of a UITableViewCell is the full width, as well (don’t quote me on that).

    • I’ve been looking at this today…since I’m working on a universal app and need to handle rotation and iPad + iPhone. I could be going about it the wrong way, but this worked for me….

      UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
      NSLog(@”%f,%f”,cell.contentView.frame.origin.x,cell.contentView.frame.size.width);

      Give’s me a 45 pixel padding in both landscape and portrait on the iPad, and therefore a width of 934 and 678 respectively.

      • I think you might be right. I noticed R.J.’s comment from back in February, above, which suggests that contentView has the correct width. Good spot!

        • Indeed, R.J.’s comment tipped me off, I was trying (and failing) to get this from the tableview…turns out grabbing a cell is what was needed.

          As always, a random blog from a year ago helped…thanks :)

          (kinda glad I wasn’t the only one looking for this).

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>