1

I have a UITableView in my iOS application, and depending on the device (iPhone or iPad), I size different items on my UITableView's contentViews.

For example, every cell's contentView has something called a valueLabel. Depending on the device, I size it properly:

if(IDIOM == IPAD)
    valueLabel = [[[UILabel alloc] initWithFrame: CGRectMake( 430.0, 0.0, 216, 44.0 )] autorelease];
else
    valueLabel = [[[UILabel alloc] initWithFrame: CGRectMake( 165.0, 0.0, 80, 44.0 )] autorelease];

Then, I configure the label (color, font, etc) and after that, I have the following lines of code:

if(IDIOM != IPAD)
     valueLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;

Turns out, when I first wrote this, I was smart for doing this. But I can't remember why. I'm trying to make an update which supports landscape mode on both the iPhone and iPad. But only the UITableView on the iPhone sizes properly in landscape mode, because for the iPad, I don't have Autoresizing. How can I have autoresizing on the iPad?

If I remove the condition if(IDIOM != IPAD), the labels don't even show up, and my cells are empty.

CodeGuy
  • 28,427
  • 76
  • 200
  • 317
  • Remove the condition `IDIOM != IPAD`? – peterp Jun 25 '11 at 18:40
  • If I remove the condition if(IDIOM != IPAD), the labels don't even show up, and my cells are empty. – CodeGuy Jun 25 '11 at 18:40
  • i assume you mean, the labels don't show up on iPhone (if you remove the conditional statement) – bshirley Jun 25 '11 at 20:23
  • often, setting the background to pink or some other garish color will help you see them, and you can watch where they may be moving when you change orientation; also `gdb` is quite useful here, break in an obvious place and `po [someView subViews]` to see all the frames of the subviews and where they might be (non visibly), it could give you a hint to the problem – bshirley Jun 25 '11 at 20:26

2 Answers2

0

Is the outer container the iPad table view is located in on the iPad resizing?

Kendall Helmstetter Gelner
  • 74,769
  • 26
  • 128
  • 150
0

I don't think views in IPad can be Autoresized. But you can manage your views according to orientation. Check my answer here.

Community
  • 1
  • 1
Nitish
  • 13,845
  • 28
  • 135
  • 263
  • Perhaps it was true at the time, but I can confirm that autoresizing *does* work on UIViews on iOS 5.0 and Xcode 4.4 – Ben Clayton Jul 31 '12 at 14:05