0

这是什么原因造成的?我在 Xcode 4.3 上运行 iOS 5.1 并使用 Storyboards。

'NSInvalidArgumentException', reason: '-[WFTopTableViewController topViewController]: unrecognized selector sent to instance 0x6d56f80'


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
    // Initial view controller is a Table View Controller, so we look up the window's rootViewController.
    UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
    // Set up the controller.
    WFTopTableViewController *controller = (WFTopTableViewController *)navigationController.topViewController;
    // Pass the controller the managed object context for the first time.
    controller.managedObjectContext = self.managedObjectContext;
    return YES;
}

谢谢!阿曼达

4

1 回答 1

3

试试这个:

(BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
    WFTopTableViewController *controller = (WFTopTableViewController*)self.window.rootViewController; 
    controller.managedObjectContext = self.managedObjectContext; 
    return YES; 
}

窗口的 rootViewController 已经是 WFTopTableViewController,而不是 UINavigationController。如果您希望反过来,请确保在 Interface Builder 中为 UINavigationController 选择“是初始视图控制器”选项。

于 2012-05-04T03:49:29.490 回答