このコードをエラーなしでコンパイルしましたが、 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];
}