【问题标题】:Instantiate ViewController with identifier causes a crash using storyboard and a xib使用故事板和 xib 使用标识符实例化 ViewController 会导致崩溃
【发布时间】:2014-06-06 19:15:49
【问题描述】:

所以我正在使用情节提要和 xib。

我在我的 ViewController 中使用了一个 tableview,它有一个自定义标题作为 xib 文件(VC 是文件所有者)。

我想在标题上滑动时展示我的新 VC,我使用 IB 向 xib 添加了滑动手势,但现在我无法展示它。

当我尝试实例化ViewControllerWithIdentifier 时发生崩溃。我为我提出的 VC 做了一个财产。并设置正确的标识符“swipeRight”。

    - (IBAction)swipedRight:(id)sender {
        NSLog(@"right");
        if (_mpvc == nil) { //user those if only so the use wont push it twice and more
            _mpvc = [self.storyboard instantiateViewControllerWithIdentifier:@"swipeRight"];
        }
[self presentViewController:_mpvc animated:YES completion:nil];
    }

错误:

Cannot find executable for CFBundle 0x9022120 </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/AccessibilityBundles/GeoServices.axbundle> (not loaded)

【问题讨论】:

标签: ios storyboard xib nib


【解决方案1】:

如果您在 XIB 文件中,您如何知道您使用的是哪个情节提要?所以首先你必须实例化包含具有指定标识符的 viewController 的故事板:

UIStoryboard *st = [UIStoryboard storyboardWithName:@"StoryboardName" bundle:nil];

在你必须用你创建的这个故事板实例化 viewController 之后:

UIViewController _mpvc = [st instantiateViewControllerWithIdentifier:@"swipeRight"];

最后你必须展示 viewController:

[self presentViewController:_mpvc animated:YES completion:nil];

希望它能解决你的问题!

【讨论】:

    猜你喜欢
    • 2018-01-25
    • 2012-01-17
    • 1970-01-01
    • 2012-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多