【问题标题】:How to create a multiple windows/views on the iPhone?如何在 iPhone 上创建多个窗口/视图?
【发布时间】:2010-10-09 12:45:49
【问题描述】:

是否可以在(基于窗口的)iPhone 应用程序中创建多个视图或窗口?

【问题讨论】:

    标签: ios objective-c iphone cocoa-touch


    【解决方案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];
    

    【讨论】:

      【解决方案2】:

      是的,有可能。只需使用视图控制器创建一个新视图并在您的类中创建该视图的实例。然后在一个 ibaction 中你可以做一些删除和添加子视图。这只是一种快速简便的方法,您可以更详细地了解如何管理每个视图等。

      按需编辑: 在您的课程中,您将在界面中创建它的一个实例,如下所示:

      MyClass *myClass; (make sure to alloc and init in the init or awakeFromNib method)
      

      然后像这样在 ibaction 中创建应用委托的实例:

      MyAppDelegate *myAppDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
      

      然后您可以这样做以从一种视图切换到另一种视图:

      [self removeFromSuperView]; (or self.view in case this is a view controller)
      [[myAppDelegate window] addSubview:myClass];
      

      【讨论】:

      • 感谢您的回答。你能给我一些例子或示例代码吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-24
      • 1970-01-01
      相关资源
      最近更新 更多