【问题标题】:Black Screen After Splash Screen iOS启动屏幕iOS后黑屏
【发布时间】:2014-09-19 17:31:14
【问题描述】:

从事高级项目,最近我的应用在启动画面后开始仅加载黑屏。我没有使用故事板。我一直在寻找解决这个问题的方法,但似乎无法为我的项目调整其他解决方案。我的 [github] (https://github.com/cleif/Hastings/tree/Fixed) 在这里有最新版本。下面是我的 AppDelegate.h 和 .m 文件中的代码。

.h

#import <UIKit/UIKit.h>
#import "IIViewDeckController.h"
#import "MenuViewController.h"
#import "HomeViewController.h"
#import "AboutViewController.h"
#import "AthleticsViewController.h"
#import "BroncoBoardViewController.h"
#import "ContactsTableViewController.h"
#import "MapViewController.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (retain, nonatomic) UIViewController *menuViewController;
@property (retain, nonatomic) UIViewController *rootViewController;

@end

.m

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize menuViewController = _menuViewController;

- (IIViewDeckController*) initializeMainViewControllers {

UIViewController *menuViewController      = [[MenuViewController alloc] init];
UIViewController *rootViewController      = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];

IIViewDeckController* deckController      = [[IIViewDeckController alloc] initWithCenterViewController:[[UINavigationController alloc] initWithRootViewController:rootViewController]
                                                                                    leftViewController:menuViewController];

return deckController;
}

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

IIViewDeckController* deckController    = [self initializeMainViewControllers];

self.menuViewController                 = deckController.leftController;
self.rootViewController                 = deckController.centerController;

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

return YES;
}

@end

对此的任何建议将不胜感激。

【问题讨论】:

  • 这种情况只发生在模拟器中吗?因为我也看到了这一点,所以将应用程序发送到后台并返回到前台似乎会带回应用程序。
  • 您的self.window 似乎为零。尝试在您的application:didFinishLaunchingWithOptions: 中添加self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

标签: ios objective-c xcode simulator


【解决方案1】:

我得到了你的代码,并在下面的行中添加了 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions,它现在工作正常

self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]]; 

所以你的 didFinishLaunchingWithOptions 方法必须是这样的

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

self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];

IIViewDeckController* deckController    = [self initializeMainViewControllers];

self.menuViewController                 = deckController.leftController;
self.rootViewController                 = deckController.centerController;

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

return YES;
}

【讨论】:

  • 最欢迎您。不用说谢谢。我喜欢帮助别人。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-27
  • 2017-03-24
相关资源
最近更新 更多