Objective-c 在我的控制器中添加子视图
我有一个与代表、控制器和其他一些东西相关的应用程序。问题是我用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的所有视图都是单个屏幕的一部分,那么在使用 viewController 设置窗口后,您不需要向窗口添加任何内容。设置您的 viewController,然后只需在该控制器的视图上添加下一个视图。
例如在您的
AppDelegate
中:然后在您的
ViewController
中:请注意,
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
:And then in your
ViewController
:Note that
init
methods are usually used to initialize values, andviewDidLoad
is usually used to set up views.