Resizing UITableView When In Landscape

Discussion in 'iOS Programming' started by macprogrammer80, Jun 1, 2009.

  1. macprogrammer80 macrumors newbie

    Apr 22, 2009
    I have an app which I have set to support landscape (which works fine) but when I turn the device on its side, the UITableView does not resize itself. What is the easiest way of
    a) Checking for the UIOrientation
    b) Adjusting the table accordingly

    What I was thinking was a simple if-else statement when laying out the table view, but it only ever runs the loop once, so when the device is rotated, it doesn't change the contents.
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    You need to set the autoResize flag of the tableview to flexible height and flexible width. Then it will resize whenever its parent view resizes.
  3. macprogrammer80 thread starter macrumors newbie

    Apr 22, 2009
    Thanks, here's the code I have:
    cellView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    The issue I have though is that the content stretches pretty much beyond readability. What I was hoping is that I can have an if-else statement comparing the current interface rotation, and re-drawing the table view info.

    Is there any way to do this, or have I done the above code wrong?
  4. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    There are a couple issues. Is the table view resizing correctly? Is the content of the table view cells being resized correctly?

    You asked about the table resizing correctly. My answer was regarding that issue.

    If the table itself is resizing correctly you need to also design your cells so they resize. You need to set the autoResizingMask correctly for the content of your cells also. In some cases the content is too complicated for that and you need to implement layoutSubviews in your UITableViewCell subclass.

    If this isn't enough info for you then show how you build your cells.

Share This Page