Wow, I lost days over this problem ... but I found a solution!
I had the same problem as yours: the "presentModalViewController: animated:" method worked only in portrait mode.
After a lot of trial and error, I found out that the reason is because I had several view controllers at the same time. I implemented a navigation system that switched between different view controllers, with one of the parents handling the children. (I could not use the UINavigationController because I needed a different look.)
So, my root view controller had a root view object and several child view controllers. When the child view controller was activated, its view object was added as a view in the view controller's root view.
The "presentModalViewController" method did not like. However, as soon as I set the parentViewController property of the child controllers, it will work!
The only problem is that the "parentViewController" is a read-only property. You must extend the UIViewController class so that you can access it.
@interface UIViewController (HelperExtension) @property (nonatomic, assign) UIViewController *parent; @end @implementation UIViewController (HelperExtension) - (UIViewController *)parent { return self.parentViewController; } - (void)setParent:(UIViewController *)parent { [self setValue:parent forKey:@"_parentViewController"]; } @end
So, whenever you add a child view controller view to your parent view controller, call the "setParent:" method after that. Then it will work!
Primaryfeather
source share