0

I am working on an iOS app with a small table view in portrait mode. And I want this view to become something totally different in landscape mode. I haven't coded it yet, but something like http://www.vertex42.com/ExcelArticles/Images/timeline/Timeline-for-Benjamin-Franklin.gif (It will be in a scroll view)

I've already read things like that: " Trying to load new view upon orientation change " but as my portrait view is a UITableView I don't know how to set the portrait view...

I'm working with a UITableViewController subclass which is initiated by the AppDelegate.

Thanks for your answer and sorry for my poor English...

EDIT : The solution : You have to create a custom UIViewController with two views which will be the tableView's delegate and data source. Then in - (BOOL)shouldAutorateTo.... You set the "hidden" property to do what you want.

/!\ Don't forget to initiate your tableView property and set its delegate and data source properties

Community
  • 1
  • 1
f.c.
  • 23
  • 5

2 Answers2

0

If you want more flexibility, take out the UITableViewController and put a UIViewController with a UITableView inside. As for the rotations, I would probably switch the UITableView for a UIScrollView on the moment of the rotation.

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
  • Thanks for your quick answer, I've learned to develop with the BNR Guide (we put the data source, the delegate in the same file) so I didn't learn it yet, is there somewhere a documentation on this alternativ? I think I will have to set this UIViewController to conform to UITableViewDelegate and DataSource protocols. Is it true? Wouldn't it be possible to make a controller hierarchy with one for landscape and one for portrait (I wouldn't have to adapt my actual TableViewController...) – f.c. Jun 25 '12 at 08:46
  • I didn't said you had to separate the `UITableViewDataSource`and the `UITableViewDelegate`... Yes you have to comply with those protocols. In my honest opinion I think you should do that now, so you can have more flexibility in the future. – Rui Peres Jun 25 '12 at 08:51
  • Ok I will do it. Thanks a lot. I'm astonished how quick I got my reply! – f.c. Jun 25 '12 at 08:54
  • If you need help for specifics let me know. You can use Omar answer once you got the `UIViewController`in place. – Rui Peres Jun 25 '12 at 09:00
  • I did it! Thanks for all! I used a combination of your answers. I created a custom ViewController working with the tableView and the customView and set the hidden with Omar's method. Thanks both of you! – f.c. Jun 25 '12 at 09:16
0

You can add an scrollview as a child of your self.view, then in your ViewController you could do this

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (UIDeviceOrientationIsLandscape(toInterfaceOrientation)) {
        tableView.hidden = YES;
        scrollView.hidden = NO;
    }
    else {
        tableView.hidden = NO;
        scrollView.hidden = YES;
    }
}
Omar Abdelhafith
  • 21,163
  • 5
  • 52
  • 56
  • Ok I try this now! Thank both of you for these quick reply! Do you know how do I get my portrait view? The one you named "tableView" I tried with self.tableView but it gives me a white screen... – f.c. Jun 25 '12 at 08:50