错误消息" Applications are expected to have a root view controller at the end of application launch"



我试图简单地在我的iPhone模拟器上查看一个空表(使用Xcode 4.2(,但不知何故我不知道我做错了什么。现在它只显示一个普通的白色页面。实际上它应该给我看一张桌子。

注意:我正在遵循Big Nerd Ranch的指南"iPhone编程",第10章的说明。

所以现在我有 4 个我的 Homepwner-App 文件:

  • HomepwnerAppDelegate.m
  • HomepwnerAppDelegate.h
  • ItemsViewController.h
  • ItemsViewController.m

"ItemsViewController"是UITableViewController的一个子类。

ItemsViewController.h

# import <UIKit/UIKit.h>
    @interface ItemsViewController : UITableViewController
@end

ItemsViewController.m

isn't filled with interesting stuff right now

HomepwnerAppDelegate.h

# import <UIKit/UIKit.h>
@class ItemsViewController;
@interface HomepwnerAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    ItemsViewController *itemsViewController; }  

@property (nonatomic, retain) IBOutlet UIWindow *window;
@end

HomepwnerAppDelegate.m

#import "HomepwnerAppDelegate.h"
#import "ItemsViewController.h"
@implementation HomepwnerAppDelegate
@synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //Create a ItemsViewController
    itemsViewController = [[ItemsViewController alloc] init];
    //Place ItemsViewController's table view in the window hierarchy
    [window addSubview:[itemsViewController view]];
    [window makeKeyAndVisible];
    return YES;
}

@end

控制台说: Homepwner[2400:207] 应用程序应在应用程序启动结束时具有根视图控制器

我知道已经有其他线程具有相同的错误消息,其中很多都链接到"didFinishLaunchingWithOptions:"- 方法,但由于他们提供了这么多解决方案,我现在很困惑,特别是因为我只是按照书中的说明,仅此而已......我只是觉得我宣布了错误的事情。如何解决问题?

我不知道

它的价值,但是,你试过吗

self.window.rootViewController = itemsViewController;

这就是我在遇到这个问题时解决它的方式。

相关内容

最新更新