0

What I would like to do is to create UIImageView without storyboard, but failed to let it show. At first I deleted storyboard, LaunchScreen.xib and Main StoryBoard file base name from info.plist. and then what I created is as follows:

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];

}

I am a beginner and couldn't find any solution. Does anybody know how to solve this? Thank you in advance.

Xcode 6.4

OSX 10.10.5

N I
  • 1
  • 1
  • 1
    I didnt see any storyboard that is loaded programmatically in ur code, and u didnt set the root controller too. You cannot create a storyboard programmatically. Either u can load it programmatically or load xibs! – Teja Nandamuri Feb 26 '16 at 17:35

1 Answers1

2

You just need to set your window's root view controller to an instance of ViewController

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

You'll also have to import ViewController.h at the top of your AppDelegate file

JordanC
  • 1,303
  • 12
  • 28