简体   繁体   English

设备上的黑屏; 模拟器工作正常

[英]Blank screen on device; simulator working fine

I am writing an iOS app with a navigation controller.我正在编写一个带有导航 controller 的 iOS 应用程序。 When I open it up on the Simulator, it runs fine.当我在模拟器上打开它时,它运行良好。 When I run it on the device, a blank screen is displayed below the status bar.当我在设备上运行它时,状态栏下方会显示一个空白屏幕。 Plus I can't figure out where my RootViewController is made to be the default view (which I suspect is the root of my problem).另外,我无法弄清楚我的 RootViewController 在哪里设置为默认视图(我怀疑这是我问题的根源)。

@class RootViewController;

@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    RootViewController *viewController;

    UINavigationController *navigationController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet RootViewController *viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    // Set the navigation controller as the window's root view controller and display.
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];

    // ...

    return YES;
}

RootViewController.m根视图控制器.m

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"Main Menu";
}

No viewWillAppear, viewDidAppear, etc.没有 viewWillAppear、viewDidAppear 等。

Displays a table of 0 elements.显示一个包含 0 个元素的表格。

- (UITableViewCell *)tableView:(UITableView *)tv
        cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    tv.backgroundColor = [UIColor whiteColor];

    UITableViewCell *cell;
    if (indexPath.row == 0)
        cell = newsCell;
    else if (indexPath.row == 1)
        cell = configureCell;
    else if (indexPath.row == 2)
        cell = aboutCell;

    return cell;
}

- (NSInteger)tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)section
{
    return 0;
}

#pragma mark UITableViewDelegate Methods


- (CGFloat)tableView:(UITableView *)tv
heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 84;
}

- (void) tableView:(UITableView *)tv
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (0 == indexPath.row)
    {
    }
    else if (1 == indexPath.row)
    {
    }
    else if (2 == indexPath.row)
    {
    }
}


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
    [tableView release];
    [newsCell release];
    [configureCell release];
    [aboutCell release];
}

RootViewController.h RootViewController.h

@interface RootViewController : UIViewController
<UITableViewDataSource, UITableViewDelegate>
{
    UITableView *tableView;
    IBOutlet UIView *displaySplashScreen;
    IBOutlet UITableViewCell *newsCell, *configureCell, *aboutCell;
}

@property (nonatomic, retain) IBOutlet UITableView *tableView;

There are a few issues here.这里有几个问题。 First, your AppDelegate header should read:首先,您的 AppDelegate header 应为:

@class RootViewController;

@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    RootViewController *rootViewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

Then, in the implementation, add the root to the navigation controller and the navController to the window like this:然后,在实现中,将根添加到导航 controller 和 navController 到 window,如下所示:

#import "RootViewController.h"

@implementation MyAppDelegate

@synthesize window;

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

    rootViewController = [[RootViewController alloc] init];
    UINavigationController *navController = [[UINavigationController alloc] 
                                             initWithRootViewController:rootViewController];

    [window addSubview:[navController view]];
    [self.window makeKeyAndVisible];

    return YES;
}

PengOne's answer is correct, except I'd make one small change. PengOne 的回答是正确的,除了我会做一点小改动。 Do this:做这个:

#import "RootViewController.h"

@implementation MyAppDelegate

@synthesize window;

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    rootViewcontroller = [[RootViewController alloc] init];
    UINavigationController *navController = [[UINavigationController alloc] 
                                         initWithRootViewController:rootViewController];

    self.window.rootViewController = navController;

    [self.window makeKeyAndVisible];
    return YES;
}

It's a better way to show a nav controller.这是显示导航 controller 的更好方法。 As PengOne also said, it has to be a problem with your Interface Builder file.正如 PengOne 所说,这一定是您的 Interface Builder 文件有问题。 Unhook everything then hook it up again to see if the problem persists.解开所有东西,然后重新连接,看看问题是否仍然存在。 If it does, check to make sure everything is named correctly.如果是这样,请检查以确保所有内容都正确命名。 Good luck!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM