我编译了这段代码没有错误,但我无法显示welcomeUIView。
是的,当我将它移入didFinishLaunchingWithOptions时,它会显示出来。但是为什么我不能按照我想要的方式去做呢?
这是控制台:
didFinishLaunchingWithOptions
view()
finished
编码:
AppDelegate.h
#import <UIKit/UIKit.h>
static UIWindow *window;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@end
AppDelegate.mm
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
std::cout<<"didFinishLaunchingWithOptions"<<std::endl;
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.rootViewController = [[UIViewController alloc] init];
view *v = new view();
v->set();
// Override point for customization after application launch.
window.backgroundColor = [UIColor whiteColor];
[window makeKeyAndVisible];
std::cout<<"finished"<<std::endl;
return YES;
}
视图.mm
#include "view.h"
#include "AppDelegate.h"
#include <UIKit/UIKit.h>
#include <iostream>
void view::set()
{
std::cout<<"view()"<<std::endl;
UIView *welcomeUIView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[welcomeUIView setBackgroundColor:[UIColor darkGrayColor]];
[welcomeUIView setHidden:false];
[window.rootViewController.view addSubview:welcomeUIView];
[window.rootViewController.view bringSubviewToFront:welcomeUIView];
}