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

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

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

      1. 何时回调已解除分配的委托?

        handle when callback to a dealloced delegate?(何时回调已解除分配的委托?)
          <tbody id='ekWgF'></tbody>
            <bdo id='ekWgF'></bdo><ul id='ekWgF'></ul>

          • <legend id='ekWgF'><style id='ekWgF'><dir id='ekWgF'><q id='ekWgF'></q></dir></style></legend>

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

              <tfoot id='ekWgF'></tfoot>

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

                  本文介绍了何时回调已解除分配的委托?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在两个类之间实现了委托回调模式,但没有保留委托.但在某些情况下,委托被解除分配.

                  I implemented the delegate-callback pattern between two classes without retaining the delegate. But in some cases, the delegate is dealloced.

                  (我的情况是我有一个 ViewController 是委托对象,当用户按下后退按钮将该 ViewController 从 NavigationController 堆栈中弹出时)

                  (My case is that I have a ViewController is the delegate object, and when the user press back button to pop that ViewController out of the NavigationController stack)

                  然后回调方法get BAD_EXE:

                  Then the callback method get BAD_EXE:

                  if (self.delegate != nil && [self.delegate respondsToSelector:selector]) {
                      [self.delegate performSelector:selector withObject:self withObject:returnObject];
                  } 
                  

                  我知道委托回调模式在很多应用程序中都实现了.您对此有何解决方案?

                  I know the delegate-callback pattern is implemented in a lot of application. What is your solution for this?

                  推荐答案

                  通常,委托应始终在其 dealloc 方法中将其与其委托对象解除关联.所以你的视图控制器应该检查它的 dealloc 是否被设置为委托类的委托,如果是,将委托属性设置为 nil.

                  Generally, a delegate should always deassociate it from its delegating object in its dealloc method. So your view controller should check in its dealloc whether it is set as the delegate of the delegating class, and if so, set the delegate property to nil.

                  在大多数情况下,我认为这不会成为问题,因为委托通常是委托对象的唯一所有者.因此,当委托被解除分配时,委托对象也将被解除分配.毕竟,这就是委托对象通常只持有对其委托的弱引用的原因.

                  In most cases, I would imagine this would not be a problem because very often the delegate is the sole owner of the delegating object. So when the delegate gets deallocated, the delegating object would get deallocated too. After all, this is the reason that delegating objects usually only hold weak references to their delegates.

                  这篇关于何时回调已解除分配的委托?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
                  Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
                  Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
                  Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
                  How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)
                  Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
                  • <i id='QUp19'><tr id='QUp19'><dt id='QUp19'><q id='QUp19'><span id='QUp19'><b id='QUp19'><form id='QUp19'><ins id='QUp19'></ins><ul id='QUp19'></ul><sub id='QUp19'></sub></form><legend id='QUp19'></legend><bdo id='QUp19'><pre id='QUp19'><center id='QUp19'></center></pre></bdo></b><th id='QUp19'></th></span></q></dt></tr></i><div id='QUp19'><tfoot id='QUp19'></tfoot><dl id='QUp19'><fieldset id='QUp19'></fieldset></dl></div>
                      <legend id='QUp19'><style id='QUp19'><dir id='QUp19'><q id='QUp19'></q></dir></style></legend>
                      • <tfoot id='QUp19'></tfoot>

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

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

                              <tbody id='QUp19'></tbody>