【问题标题】:Nil modal viewcontroller objectNil 模态视图控制器对象
【发布时间】:2015-03-20 11:20:25
【问题描述】:

在我的 gameScene 中,我使用它来断开连接。但本质上是移动viewController。

游戏场景

@implementation

gameController = [[GameViewController alloc] init];

-(void)disconnect {       
    [gameController disconnectAction];
}

@interface

GameViewController *gameController;

GameViewController

@interface

#import "ConnectionsViewController.h"

-(void)disconnectAction;

@implementation

-(void)disconnectAction {
    ConnectionsViewController *game = [self.storyboard instantiateViewControllerWithIdentifier:@"ConnectionsViewController"];

    [self presentViewController:game animated:YES completion:nil];
}

但是,这会返回trying to modal a nil viewcontroller 的错误。是的,故事板 ID 是正确的。我也试过了

UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

但是,这会返回 nil 故事板异常。

【问题讨论】:

  • self.storyboard 为零吗?
  • @Larme 没错,它是从 viewController 运行的,它导入了 viewController >:|
  • 你是如何显示GameViewController的?
  • @Larme 场景呈现在 GameViewController 中,即[skView presentScene:scene];

标签: ios objective-c iphone


【解决方案1】:

使用下面的想法...可能对您有帮助..

-(void)disconnectAction {
    [self performSegueWithIdentifier:@"ConnectionsViewController" sender:nil];
}

Make sure that you have to set view controller relationship in your storyboard.

【讨论】:

  • 当你说确保我已经设置了一个关系时,这是否仅仅意味着一个故事板 ID?
  • Chadasama 我得到一个 has no segue with identifier 错误。
  • 我所有其他的视图控制器都与我提供的代码完美结合。但是,在存在 skscene 的情况下尝试执行此操作时,我遇到了这个问题。
  • 此外,最重要的是。在 performSegue 方法之后,它运行 GameViewController viewDidLoad 方法。而不是移动控制器。这是一个如此奇怪的情结。
  • 这很简单,你只需要把这段代码和设置关系放在你的故事板中..这会起作用......你要获取的究竟是什么问题.. ConnectionsViewController 只是类..没有查看?
【解决方案2】:

我需要设置一个@protocol & 委托,以便运行该方法来移动视图控制器。

How do I present a UIViewController from SKScene?

这帮助很大。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多