Objective-c在我的控制器中添加子视图 [英] Objective-c Adding subViews in my controller

查看:155
本文介绍了Objective-c在我的控制器中添加子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代表,控制器和其他一些东西的应用程序。问题是我使用init初始化控制器中的所有内容。这个init创建了3个UIVIews(openGL,imagepickerview和MKMapView),我想在窗口中添加这些视图,因此它们位于另一个之上。但是,不知何故,它只绘制了3个imagePickerView中的一个。这是委托:

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;
}

这里是控制器:

-(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];
}

我做得好吗?

推荐答案

假设您的所有视图都是单个屏幕的一部分,则无需在窗口后添加任何内容使用viewController进行设置。设置viewController,然后在该控制器的视图中添加下一个视图。

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.

例如。在你的 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 通常用于设置视图。

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

这篇关于Objective-c在我的控制器中添加子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆