【问题标题】:viewDidLoad is not called after the setting of no storyboard设置no storyboard后不调用viewDidLoad
【发布时间】:2016-02-26 17:32:45
【问题描述】:

我想做的是创建没有情节提要的 UIImageView,但未能让它显示。起初我从 info.plist 中删除了storyboardLaunchScreen.xibMain 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

【问题讨论】:

  • 我没有看到任何在你的代码中以编程方式加载的故事板,你也没有设置根控制器。您不能以编程方式创建情节提要。您可以以编程方式加载它或加载 xibs!

标签: ios objective-c iphone programmatically-created


【解决方案1】:

您只需将窗口的根视图控制器设置为 ViewController 的实例

self.window.rootViewController = [[ViewController alloc] init];

您还必须在 AppDelegate 文件的顶部导入 ViewController.h

【讨论】:

  • 有效!你真的帮了我大忙。非常感谢!
  • @NI 没问题。有机会请采纳我的回答
猜你喜欢
  • 2012-12-11
  • 2014-09-28
  • 2012-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-09
  • 2013-06-11
相关资源
最近更新 更多