[英]viewDidLoad is not called after the setting of no storyboard
我想做的是創建沒有情節提要的UIImageView,但是無法顯示它。 首先,我從info.plist中刪除了storyboard
, LaunchScreen.xib
和Main StoryBoard file base name
。 然后我創建的內容如下:
AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor greenColor];
[self.window makeKeyAndVisible];
return YES;
}
ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *imageData =[UIImage imageNamed:@"aaa.png"];
UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 30, 100, 100)];
myImage.image = imageData;
[self.view addSubview:myImage];
}
我是一個初學者,找不到任何解決方案。 有人知道如何解決這個問題嗎? 先感謝您。
Xcode 6.4
OSX 10.10.5
您只需要將窗口的根視圖控制器設置為ViewController的實例
self.window.rootViewController = [[ViewController alloc] init];
您還必須在AppDelegate文件的頂部導入ViewController.h
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.