can't add UIView from a UIViewController
I have some issue showing a view from a view controller. Basically, I have a UIViewController class, I programmatically created the view by overloading loadView method. Here is the code that I have:
UIView* view = controller.view;
UIWindow* window = [UIApplication sharedApplication].keyWindow;
i开发者_C百科f(!window)
{
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
}
[window addSubview:view];
The view is not visible.
However, if I created a simple view based app by calling
[self presentModalViewController: controller animated: YES];
Everything works well.
I am new to the iOS View Programming. Anything I did was wrong?
Steve,
I'm not sure what you are trying to achieve here, but a typical iphone app will have a base UIViewController subclass, say a nav controller or tab controller and that controller's view is added as a subview of the UIWindow view in the appDelegate class.
You then instantiate further UIViewControllers or subclasses thereof and those views get added as subviews of the current view and so on.
Have you checked out the basic templates in XCode? These should show you how the appDelegate and the like works. You generally don't need to mess with UIWindow in other classes, in my experience.
精彩评论