Main.storyboard无法加载

时间:2014-05-29 15:30:35

标签: ios objective-c xcode

我是iOS的新手,我正在做一些练习,我一开始就陷入困境。我想使用标准的Main.storyBoard,如下所示: enter image description here

AppDelegate.m文件如下所示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
//    CGRect bounds = [[UIScreen mainScreen] bounds];
//    self.window = [[UIWindow alloc] initWithFrame:bounds];
//    
//    self.controler = [[ViewController alloc] init];
//    
//    self.window.rootViewController = self.controler;
//    
//    [self.window makeKeyAndVisible];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
    UIViewController *vc = [storyboard instantiateInitialViewController];

    // Set root view controller and make windows visible
    self.window.rootViewController = vc;
    [self.window makeKeyAndVisible];



    return YES;
}

ViewControler是否有用:

@interface ViewController ()

@property UIView *viewM;

@end

@implementation ViewController

-(void) loadView
{
    CGRect bounds = [[UIScreen mainScreen] bounds];

    self.viewM = [[UIView alloc] initWithFrame: bounds];
    self.view = self.viewM;

}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"AHAHH DOTKNIETO EKRANU");
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    self.view.backgroundColor = [UIColor blueColor];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];


    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 200, 50)];

    //SET TEXT FOR THIS LABEL

    label.text = @"TEXTTTTTT";
    [self.view addSubview:label];

    // Do any additional setup after loading the view, typically from a nib.
}

每次我运行此示例时,它都会加载我查看哪个是白色而不是上面的图像。什么是不对的?我正在使用Xcode 5.1.1版本。

1 个答案:

答案 0 :(得分:3)

在项目 - 常规页面中,您应该看到"主界面"的设置。

删除applicationDidFinishLaunching中除return YES;以外的所有代码,并确保将其设置为Main

enter image description here