<legend id='5BgUz'><style id='5BgUz'><dir id='5BgUz'><q id='5BgUz'></q></dir></style></legend>
      <bdo id='5BgUz'></bdo><ul id='5BgUz'></ul>
    <i id='5BgUz'><tr id='5BgUz'><dt id='5BgUz'><q id='5BgUz'><span id='5BgUz'><b id='5BgUz'><form id='5BgUz'><ins id='5BgUz'></ins><ul id='5BgUz'></ul><sub id='5BgUz'></sub></form><legend id='5BgUz'></legend><bdo id='5BgUz'><pre id='5BgUz'><center id='5BgUz'></center></pre></bdo></b><th id='5BgUz'></th></span></q></dt></tr></i><div id='5BgUz'><tfoot id='5BgUz'></tfoot><dl id='5BgUz'><fieldset id='5BgUz'></fieldset></dl></div>

      <small id='5BgUz'></small><noframes id='5BgUz'>

      <tfoot id='5BgUz'></tfoot>

    1. 如何检查视图控制器是否可以执行转场

      时间:2023-05-30
      <tfoot id='GZny5'></tfoot>

    2. <i id='GZny5'><tr id='GZny5'><dt id='GZny5'><q id='GZny5'><span id='GZny5'><b id='GZny5'><form id='GZny5'><ins id='GZny5'></ins><ul id='GZny5'></ul><sub id='GZny5'></sub></form><legend id='GZny5'></legend><bdo id='GZny5'><pre id='GZny5'><center id='GZny5'></center></pre></bdo></b><th id='GZny5'></th></span></q></dt></tr></i><div id='GZny5'><tfoot id='GZny5'></tfoot><dl id='GZny5'><fieldset id='GZny5'></fieldset></dl></div>
    3. <legend id='GZny5'><style id='GZny5'><dir id='GZny5'><q id='GZny5'></q></dir></style></legend>
        <tbody id='GZny5'></tbody>

        <small id='GZny5'></small><noframes id='GZny5'>

        • <bdo id='GZny5'></bdo><ul id='GZny5'></ul>

                本文介绍了如何检查视图控制器是否可以执行转场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                这可能是一个非常简单的问题,但在搜索时没有产生任何结果,所以在这里......

                This might be a very simple question but didn't yield any results when searching for it so here it is...

                我正在尝试找出一种方法来检查某个视图控制器是否可以在调用 performSegueWithIdentifier: 方法之前执行带有标识符 XYZ 的 segue.

                I am trying to work out a way to check if a certain view controller can perform a segue with identifier XYZ before calling the performSegueWithIdentifier: method.

                类似的东西:

                if ([self canPerformSegueWithIdentifier:@"SegueID"])
                    [self performSegueWithIdentifier:@"SegueID"];
                

                可能吗?

                推荐答案

                如文档所述:

                应用程序通常不需要直接触发 segue.相反,您在 Interface Builder 中配置一个与视图控制器,例如嵌入在其视图层次结构中的控件,触发segue.但是,您可以调用此方法来触发以编程方式进行 segue,也许是为了响应某些无法执行的操作在情节提要资源文件中指定.例如,您可能从用于处理抖动的自定义操作处理程序调用它或加速度计事件.

                Apps normally do not need to trigger segues directly. Instead, you configure an object in Interface Builder associated with the view controller, such as a control embedded in its view hierarchy, to trigger the segue. However, you can call this method to trigger a segue programmatically, perhaps in response to some action that cannot be specified in the storyboard resource file. For example, you might call it from a custom action handler used to process shake or accelerometer events.

                收到此消息的视图控制器必须已加载从故事板.如果视图控制器没有关联的故事板,也许是因为你自己分配和初始化了它,此方法抛出异常.

                The view controller that receives this message must have been loaded from a storyboard. If the view controller does not have an associated storyboard, perhaps because you allocated and initialized it yourself, this method throws an exception.

                话虽如此,当您触发 segue 时,通常是因为假设 UIViewController 将能够使用特定的 segue's 标识符.我也同意 Dan F,您应该尽量避免可能引发异常的情况.作为你不能做这样的事情的原因:

                That being said, when you trigger the segue, normally it's because it's assumed that the UIViewController will be able to respond to it with a specific segue's identifier. I also agree with Dan F, you should try to avoid situations where an exception could be thrown. As the reason for you not to be able to do something like this:

                if ([self canPerformSegueWithIdentifier:@"SegueID"])
                    [self performSegueWithIdentifier:@"SegueID"];
                

                我猜:

                1. respondsToSelector: 仅检查您是否能够在运行时处理该消息.在这种情况下你可以,因为类 UIViewController 能够响应 performSegueWithIdentifier:sender:.要实际检查一个方法是否能够处理带有某些参数的消息,我想这是不可能的,因为为了确定是否有可能它必须实际运行它,并且在这样做时 NSInvalidArgumentException会上升.
                2. 要实际创建您建议的内容,接收 UIViewController 关联的 segue id 列表会很有帮助.从 UIViewController 文档,我找不到任何类似的东西
                1. respondsToSelector: only checks if you are able to handle that message in runtime. In this case you can, because the class UIViewController is able to respond to performSegueWithIdentifier:sender:. To actually check if a method is able to handle a message with certain parameters, I guess it would be impossible, because in order to determine if it's possible it has to actually run it and when doing that the NSInvalidArgumentException will rise.
                2. To actually create what you suggested, it would be helpful to receive a list of segue's id that the UIViewController is associated with. From the UIViewController documentation, I wasn't able to find anything that looks like that

                就目前而言,我猜你最好的选择是继续使用 @try @catch @finally.

                As for now, I am guessing your best bet it's to keep going with the @try @catch @finally.

                这篇关于如何检查视图控制器是否可以执行转场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:iOS - 如何创建“实用程序"?我的所有控制器都 下一篇:iOS:UISplitViewController 无法推送到 UINavigationControl

                相关文章

                最新文章

                  <small id='2Pv1m'></small><noframes id='2Pv1m'>

                  <i id='2Pv1m'><tr id='2Pv1m'><dt id='2Pv1m'><q id='2Pv1m'><span id='2Pv1m'><b id='2Pv1m'><form id='2Pv1m'><ins id='2Pv1m'></ins><ul id='2Pv1m'></ul><sub id='2Pv1m'></sub></form><legend id='2Pv1m'></legend><bdo id='2Pv1m'><pre id='2Pv1m'><center id='2Pv1m'></center></pre></bdo></b><th id='2Pv1m'></th></span></q></dt></tr></i><div id='2Pv1m'><tfoot id='2Pv1m'></tfoot><dl id='2Pv1m'><fieldset id='2Pv1m'></fieldset></dl></div>

                  <legend id='2Pv1m'><style id='2Pv1m'><dir id='2Pv1m'><q id='2Pv1m'></q></dir></style></legend>

                    <bdo id='2Pv1m'></bdo><ul id='2Pv1m'></ul>
                1. <tfoot id='2Pv1m'></tfoot>