Objective-c Adding subViews in my controller

我与影子孤独终老i 提交于 2019-12-20 05:19:14

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5501611/objective-c-adding-subviews-in-my-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!