ios - 使用标识符实例化 ViewController 会导致使用 Storyboard 和 xib 崩溃

标签 ios storyboard xib nib

所以我正在使用 Storyboard和 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)

最佳答案

如果您在 XIB 文件中,您如何知道您使用的是哪个 Storyboard?因此,首先您必须实例化 Storyboard,其中包含具有指定标识符的 viewController:

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

在您必须使用您创建的这个 Storyboard实例化 viewController 之后:

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

最后你必须呈现 viewController:

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

希望它能解决您的问题!

关于ios - 使用标识符实例化 ViewController 会导致使用 Storyboard 和 xib 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23219165/

相关文章:

ios - 将历史数组值插入 UITableViewController

ios - 使用 NSLayout 设置 UILabel 的 X 和 Y 值

ios - 如何从 native ios View 弹出回 flutter View ?

swift - 从 Storyboard 创建 Swift 代码

ios - Swift 3 - 从另一个类中的 XIB 实例访问变量

ios - Swift 将文本分配给 xib 文件中的标签

objective-c - 我的 XIB for iPad/iPhone 中的两个 UITableViewCells

iphone - 如何在ios 6 Xcode中禁用IOS约束?

ios - macOS 和 iOS 上的 libnl

ios - Swift 如何以编程方式移动 UIButton?