是否可以在(基于窗口的)iPhone应用程序中创建多个视图或窗口?
答案 0 :(得分:2)
是的可能。只需使用视图控制器创建一个新视图,然后在您的类中创建该视图的实例。然后在一个ibaction中你可以做一些删除和添加子视图。这只是一种快速简便的方法,您可以通过管理每个视图等方式获得更多细节。
根据要求修改 在您的课程中,您将在界面中创建它的实例,如下所示:
MyClass *myClass; (make sure to alloc and init in the init or awakeFromNib method)
然后在ibaction中创建app委托的实例,如下所示:
MyAppDelegate *myAppDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
然后你可以这样做从一个视图切换到另一个视图:
[self removeFromSuperView]; (or self.view in case this is a view controller)
[[myAppDelegate window] addSubview:myClass];
答案 1 :(得分:1)
您可以执行以下操作以编程方式添加视图:
//If you create controllers via XCode, just link them in the .h file with IBOutlet
UIViewController *aViewController = [[UIViewController alloc] initWithNibName:@"YourNibName" bundle:[NSBundle mainBundle]];
self.viewController = aViewController;
[aViewController release];
// Add the view controller's view as a subview of the window
UIView *controllersView = [viewController view];
[window addSubview:controllersView];
[window makeKeyAndVisible];