黑屏试图在Splash之后放一个.Xib

时间:2014-10-02 11:50:10

标签: ios8

我正在为iOS 8编写应用程序。我遇到了一个问题,因为我不想使用故事板,我想在第一时间放置一个.xib文件。很难的问题是,在飞溅之后总是黑屏。

我想在Splash之后放置的类是LoginViewController

在一般选项中,“主界面”为白色(空)(如果放入类的名称,我有NSException(NSUknownException))。

在.xib文件中我已经连接了文件所有者,并且在屏幕的右侧我在“自定义类”(LoginViewController)中有了类的名称。

我的appDelegate.h是:(我尝试使用“@property(强,非原子)LoginViewController * viewController;”也是)

#import <UIKit/UIKit.h>
#import "LoginViewController.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIViewController *viewController;


@end

我的appDelegate.m是:(我尝试了很多变种)

#import "AppDelegate.h"
#import "LoginViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.viewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
    navController.navigationBarHidden = YES;

    self.window.rootViewController = navController;
    [self.window makeKeyAndVisible];

    return YES;

}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

LoginViewController.h:

#import <UIKit/UIKit.h>

@interface LoginViewController : UIViewController
{

    IBOutlet UILabel *labelPrueba;
    IBOutlet UIButton *botonPrueba;

    IBOutlet UIButton *boton2prueba;
    IBOutlet UILabel *label2Prueba;

    IBOutlet UILabel *dsfd;
    IBOutlet UIButton *dfdf;
}

@end

LoginViewController.m:

#import "LoginViewController.h"

@interface LoginViewController ()

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    label2Prueba.text = @"laaaaaaaaaaaaa";
    NSLog(@"Entra en viewDidLoad");

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

有人可以帮助我。我疯了似的。

非常感谢。

1 个答案:

答案 0 :(得分:0)

解决方案是把这个窗口像init框架一样:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // That was the solution  
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // That was the solution

    self.viewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
    navController.navigationBarHidden = YES;

    self.window.rootViewController = navController;
    [self.window makeKeyAndVisible];

    return YES;
}

由于