[英]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.