UIScrollView does not rotate to landscape - iphone

This is most def something very simple, but it is driving me crazy, cant figure it out.
It was very simple, see solution below
My app does not auto rotate. It is just stuck in portrait.
My AppDelegate creates a viewController witch has shouldAutorotate uncommented an simply returns yes.
My viewController sets up a scrollview(x) as it's view and adds a subclassed custom scrollview(y) as its subview.
Than scrollview(y) adds UIView as it's subview. This UIView acts as a content view and has 1 or multiple other UIViews as subview.
So: AppDelegate -> scrollView(x) -> scrollView(y) -> UIView -> 1 or more UIView's
I have a line displayed when shouldAutorotate is called. This happens 2x when the application has finished loading. When I rotate the simulator, nothing happens, shouldAutorotate is not called apparently because I don't see a line displayed in my log.
Is there a property on the UIScrollview which prevents it from rotating?
Update: I've just changed my plist.info to start the app in landscape. Now the app is stuck in landscape and does not rotate to portrait.
FYI: I'm not using interface builder, all done in code.

Solution: Turns out I was a bit to memory conservative. In my app delegate I would create an instance of a viewController, add it to the window, and than called release on it, figuring it was added to the window so I wouldn't need it anymore. Bad idea.
The shouldAutorotate messages is therefore sent to an object that does not exist anymore. I did get a message in my console about a message being sent to a released object, but only multiple seconds (20 or so) after I rotated the simulator.
I've learned that you should always keep a reference to your "main/root viewController" as an instance variable in appDelegate

Related

Handle interafce orientation change happened beyond my viewController

I have UIViewController that acts like container for several other viewcontrollers. Each of that sub-viewControllers is added as a child, and only one can be visible at the moment. The problem is: when I rotate the device, container viewController handles rotation properly, as well as currently displayed child view controller. Off screen view controllers are resized properly as well, but don't receive any messages and I don't know when I should update it's contents. Is there any method of handling this, or should I instead do this all manually, e.g. storing last orientation for each viewcontroller, checking in viewWillAppear: if orientation has changed and do update manually if nescessary?
You have to check [UIApplication sharedApplication].statusBarOrientation in viewWillAppear: and adjust your views appropriately.
Also you can send orientation change message to child viewControllers, as explained here.

UITableView does not work after switching rootViewController?

I couldn't find any tutorial that i could understand about switching views but i found out that i can switch them by changing the window's rootViewController property.
The problem is my other view has 2 UITableViews in it, but they don't respond to swipes when the controller just became the rootViewController, but after i turn my ipad 90 degrees the view changes to landscape then it starts to work.
Can anyone tell me how to make them work when the view is loaded?
You can't change directly the windows rootViewController property and have it to work, because the system doesn't get notify that that change occurred. That is why the change took effect only when the system asked for that view again.
You need to use a method to change it. Depending on your architecture you may want to use a method from UIViewController
transitionFromViewController:toViewController:duration:options:animations:completion:
UINavigationController :
setViewControllers:animated:
UIView :
transitionFromView:toView:duration:options:completion:

setNeedsDisplay works on iPhone but not on iPad

The view in question was created in IB on the root view and wired to a class method in the rootViewController. In the view's class method I am overriding drawRect to draw it's content. I am calling setNeedsDisplay on the view from the rootViewController after the user changes some parameters.
On the iPhone this works fine. On the iPad, however, drawRect in the class method does not get called.
I suspect that the reason for this has to do with the drawing cycle. On the iPhone the view used by the user to change the parameters is pushed onto the screen over the view in question. On the iPad this view is added to the root view above, not over, the view in question. So when the view used to change the parameters is closed, unlike on the iPhone, a drawing cycle is not generated and so the invalidated view is not updated.
I'm stuck. Any help would be appreciaetd.
Found the problem...
I discovered that in the xib being used by the root view controller for the iPad, the wiring for the UIView object in question was some how corrupted. When I hovered over the bullet of it's iIBOutlet variable in the .h file an UISegmentedControl elsewhere in the xib would be selected instead of the intended UIView. Right-Clicking the UISegmentedControl did not show that the link existed. The only way I was able to get it fixed was to remove all the wiring from both objects and rewire them properly. Calling setNeedsDisplay now works. as expected, on the iPad just like it does on the iPhone.

Subviews disappearing from UIViewController

I have application with multiple UIViewControllers using navigation controller. UIViewController contains tableView, searchbar (that I can show/hide) and toolbar. All of this is added as subviews to its view. All this subviews are created after UIViewController is initialized and their content depend on UIVievController's content.
It works fine expect one problem. When I play with my app a little, move back and forth, open some modal views etc sometimes after navigating back to my root VC all it's subviews dissapear and all I get is white screen.
I double checked all my code and I can't find source of problem (I certainly don't remove them myself). I wasn't able to find exact patern how to reproduce this, it seems random. Any idea why iphone would remove my subviews from VC? I would post some code, but I don't want to put it all here and I am not sure which part is important, so if you wish to see some, let me know
Add your views in loadView or viewDidLoad: when viewDidUnload is called, the view is released, so they need to be created again when the view is shown again.

iphone - TabBarController rotation question

My app has 4 tabs. All the view controllers support rotation, and indeed are rotated when I rotate the device. For one of the view controllers, I need to reposition some of the subviews upon rotation. I do this in willRotateToInterfaceOrientation of that view controller, and it works fine.
The problem comes when I switch to a different tab, then rotate the device, then go back to the original tab. It apparently has not received the rotation notification, since willRotateToInterfaceOrientation has not been called. So it seems as though only the "active" view controller gets notified that the device has rotated.
The question: how do you get all the view controllers (controlled by a TabBarController) to rotate?
Unfortunately this is a bug in iOS 3.x. It works fine in iOS 4.x. I've seen apps that manually keep track of orientation changes and then do the rotation manually for inactive viewcontrollers. Sucks.
Looking through the iOS 3.2 docs to make sure this works, there is a viewControllers property in UITabBarController. Try something like this:
for (UIViewController * viewController in tabBarController) {
// Do stuff here with each 'viewController'.
}
I recommend that you do something with the UIViewController's -shouldAutorotateToInterfaceOrientation: method but you may have another way in which you plan on achieving the rotation.
You should also check for the interface orientation in viewWillAppear method of the controller whose subviews frame you are changing.Because when you move to the new tab and rotate the device and now when you tap another tab the viewWillAppear method will we called and there you can change the frames accordingly.
I also faced the same problem which i sorted out using this approach