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

      1. <small id='KLD2o'></small><noframes id='KLD2o'>

          <bdo id='KLD2o'></bdo><ul id='KLD2o'></ul>
      2. Objective-C 等价于 Java 在类方法中的匿名类

        时间:2024-08-25
        <i id='NeChd'><tr id='NeChd'><dt id='NeChd'><q id='NeChd'><span id='NeChd'><b id='NeChd'><form id='NeChd'><ins id='NeChd'></ins><ul id='NeChd'></ul><sub id='NeChd'></sub></form><legend id='NeChd'></legend><bdo id='NeChd'><pre id='NeChd'><center id='NeChd'></center></pre></bdo></b><th id='NeChd'></th></span></q></dt></tr></i><div id='NeChd'><tfoot id='NeChd'></tfoot><dl id='NeChd'><fieldset id='NeChd'></fieldset></dl></div>
        • <tfoot id='NeChd'></tfoot>
            <bdo id='NeChd'></bdo><ul id='NeChd'></ul>

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

              <legend id='NeChd'><style id='NeChd'><dir id='NeChd'><q id='NeChd'></q></dir></style></legend>
                <tbody id='NeChd'></tbody>

                  本文介绍了Objective-C 等价于 Java 在类方法中的匿名类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I want to set the delegate of an object inside a class method in Objective-C. Pseudo-code:

                  + (ClassWithDelegate*) myStaticMethod {
                      if (myObject == nil) {
                          myObject = [[ClassWithDelegate alloc] init];
                          // myObject.delegate = ?
                      }
                      return myObject;
                  }
                  

                  In Java I would simply create an anonymous class that implemented the delegate protocol. How can I do something similar in Objective-C?

                  Basically I would like to avoid creating a separate class (and files) to implement a simple delegate protocol.

                  解决方案

                  There are currently no anonymous classes in Objective-C.

                  Often you can use an already existing object. For instance, for an NSTableViewDataSource, you can implement the methods in the document or view controller and pass that as the delegate.

                  Or you can have the object itself implement the protocol and make it its own delegate in the default case.

                  Or the methods that send the delegate messages can check for a nil delegate and do something sensible in that situation.

                  Or you can declare and define a class inside the implementation file you are creating the object that needs a delegate.

                  这篇关于Objective-C 等价于 Java 在类方法中的匿名类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:自动委托 java 类的所有方法 下一篇:如何将实现委托给 Kotlin 中的可变属性?

                  相关文章

                    <bdo id='EgiPq'></bdo><ul id='EgiPq'></ul>
                1. <tfoot id='EgiPq'></tfoot>

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

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

                    1. <legend id='EgiPq'><style id='EgiPq'><dir id='EgiPq'><q id='EgiPq'></q></dir></style></legend>