是否可以在实例化对象之前检查故事板中是否存在标识符? [英] Is it possible to check whether an identifier exists in a storyboard before instantiating the object?

查看:83
本文介绍了是否可以在实例化对象之前检查故事板中是否存在标识符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中我有这一行,但我想知道是否有办法检查 @SomeController是否存在,然后再将它与 instantiateViewControllerWithIdentifier 一起使用方法。如果标识符不存在则应用程序崩溃。

In my code I have this line, but I was wondering if there is way to check whether @"SomeController" exists before I use it with the "instantiateViewControllerWithIdentifier" method. If the identifier doesn't exist then the app crashes.

如果没有一个好的方法,这不是一个大问题,我可以只是一点点更加小心,不要指责标识符名称,但我希望我能更优雅地处理它。

It's not a huge problem if there isn't a good way to do it, I can just be a bit more careful not to fat finger the identifier names, but I was hoping I could handle it more gracefully.

UIViewController *newTopViewController = [self.storyboard    instantiateViewControllerWithIdentifier:@"SomeController"];


推荐答案

不,没有检查。但是,您不需要。如果标识符不存在,此方法将返回 nil ,因此只需使用 NSAssert 检查该方法。

No, there is no check for this. However, you don't need to. This method will return nil if the identifier doesn't exist, so just check for that with an NSAssert.

编辑其实这是错误的!!这很奇怪......文档的返回值部分与另一部分相矛盾......但答案仍然是最终没有(没有方法来检查是否存在标识符)

EDIT Actually this is wrong!! That's weird...the return value section of the documentation contradicts another portion...but still the answer is ultimately no (there is no method to check for the existence of an identifier)

这篇关于是否可以在实例化对象之前检查故事板中是否存在标识符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆