이 코드는 오류없이 컴파일되었지만 welcomeUIView을 표시 할 수 없습니다.RootViewController는 대리자 외부에서 액세스 할 때 하위 뷰를 추가하지 않습니다.
예, 안으로 들어가면 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;
}
,174,
view.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];
}