Objective-c 在我的控制器中添加子视图

发布于 2024-10-27 21:27:33 字数 833 浏览 1 评论 0原文

我有一个与代表、控制器和其他一些东西相关的应用程序。问题是我用 init 初始化了控制器中的所有内容。此 init 创建 3 个 UIVIew(openGL、imagepickerview 和 MKMapView),我希望将这些视图添加到窗口中,因此它们位于另一个视图之上。然而,不知何故,它只绘制了 3 个图像之一,即 imagePickerView。这里是代表:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.rootViewController = self.viewController;
    viewController = [[ARInvadersViewController alloc] initWithWindow:self.window];
    return YES;
}

这里是控制者:

-(id)initWithWindow:(UIWindow *)_window{
    self.window = _window;
    // ...
    // Some code here
    // ...
    [self.window addSubview:imagePickerController.view];
    [self.window addSubview:self.glView];
    [self.window addSubview:mapView];
    [self.window makeKeyAndVisible];
}

我做得好吗?

I have an aplication with the delegate, the controller and some other things. The thing is that i initzialize everything in the controller with init. This init creates 3 UIVIews (openGL, imagepickerview and a MKMapView) and I want these views to be added in the window, so they are on top of the other. However, somehow it only paints one of the 3, the imagePickerView. Here is the delegate:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.rootViewController = self.viewController;
    viewController = [[ARInvadersViewController alloc] initWithWindow:self.window];
    return YES;
}

And here the controller:

-(id)initWithWindow:(UIWindow *)_window{
    self.window = _window;
    // ...
    // Some code here
    // ...
    [self.window addSubview:imagePickerController.view];
    [self.window addSubview:self.glView];
    [self.window addSubview:mapView];
    [self.window makeKeyAndVisible];
}

Am I Doing it OK?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽你眉间 2024-11-03 21:27:33

假设您的所有视图都是单个屏幕的一部分,那么在使用 viewController 设置窗口后,您不需要向窗口添加任何内容。设置您的 viewController,然后只需在该控制器的视图上添加下一个视图。

例如在您的 AppDelegate 中:

[self.window addSubview:self.viewController.view];  
[self.window makeKeyAndVisible];

然后在您的 ViewController 中:

- (void)viewDidLoad {
    [super viewDidLoad];

    // blah blah blah

    [self.view addSubview:imagePickerController.view];
    [self.view addSubview:self.glView];
    [self.view addSubview:mapView];
}

请注意,init 方法通常用于初始化值,而 viewDidLoad 方法通常用于初始化值。 code> 通常用于设置视图。

Assuming that all of your views are part of a single screen, you don't need to add anything to your window after setting it up with your viewController. Set your viewController and then just add the next views on that controller's view.

e.g. in your AppDelegate:

[self.window addSubview:self.viewController.view];  
[self.window makeKeyAndVisible];

And then in your ViewController:

- (void)viewDidLoad {
    [super viewDidLoad];

    // blah blah blah

    [self.view addSubview:imagePickerController.view];
    [self.view addSubview:self.glView];
    [self.view addSubview:mapView];
}

Note that init methods are usually used to initialize values, and viewDidLoad is usually used to set up views.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文