应用程序在创建ViewController对象时崩溃

时间:2014-03-29 08:55:33

标签: ios iphone objective-c ios7

在我的应用程序中,当我尝试创建一个viewController类的对象时,我需要从appDelegate显示为landingScreen,我的应用程序崩溃了。

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

它转到initWithNibName类的DiscoverViewController方法,但在[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]崩溃。

我附上的堆栈跟踪截图。我已经启用了ExceptionalBreakpoint并启用了NSZombie,但仍然很难运气。 任何帮助,将不胜感激。谢谢!

添加

    self.navigationController = [[[UINavigationController alloc]initWithRootViewController:self.viewController]autorelease];
self.window.rootViewController = self.navigationController;

Xcode 4.6 设备iOS - 7.1

enter image description here

1 个答案:

答案 0 :(得分:0)

将它写在AppDelegate.h .......

     #import <UIKit/UIKit.h>
     @class DiscoverViewController;

 @interface AppDelegate : UIResponder <UIApplicationDelegate>

 @property (strong, nonatomic) UIWindow *window;
 @property (nonatomic,retain)  UINavigationController *nav;
 @property (strong, nonatomic) DiscoverViewController *viewController;

 @end

并在AppDelegate.m中编写....

  #import "AppDelegate.h"
  #import "DiscoverViewController.h"

  @implementation AppDelegate

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
   {
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    
     self.viewController = [[DiscoverViewController alloc] initWithNibName:@"DiscoverViewController" bundle:nil];

     UINavigationController *nav =[[UINavigationController alloc]initWithRootViewController:self.viewController];

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

    return YES;
  }



@end