目标c-在运行我的第一个iOS应用程序时获得SIGABRT



尝试使用Xcode 5.1编写我的第一个iPhone应用程序。这是我AppDelegate代码的一部分

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    self.viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"AddViewController"];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window setRootViewController:self.viewController];
    [self.window addSubview:self.navigationController.view];
    [self.window makeKeyAndVisible];
    return YES;
}

我有一个名为"Main.storyboard"的故事板,其中包含导航控制器视图控制器

当我运行我的应用程序时,我会得到SIGABRT error with NSInternalInconsistencyException exception

有人能帮我纠正这个错误吗?

谢谢。

为什么要将子视图添加为UINavigationController.view,将根视图添加为view-controller?您的代码必须如下所示:-

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    self.viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"AddViewController"];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window setRootViewController:self.navigationController];
    [self.window makeKeyAndVisible];
    return YES;
}

并验证您的视图控制器的标识符是否设置正确,您是否在上面给出。

试试这个

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  UIStoryboard *storyBord = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:[NSBundle  mainBundle]];
  self.window.rootViewController = [storyBord instantiateInitialViewController] ;
 [self.window makeKeyAndVisible];
 return YES;
}

如果使用序列图像板作为主界面,则不需要设置任何代码。因此,您可以将UINavigationController添加到情节提要中的场景中。然后使用连接检查器设置rootViewController。

查看视频了解:链接

代码将如下所示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}

最新更新