<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 在类方法中的匿名类

        Objective-C equivalent to Java#39;s anonymous classes in class methods(Objective-C 等价于 Java 在类方法中的匿名类)
        <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 在类方法中的匿名类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                    <bdo id='EgiPq'></bdo><ul id='EgiPq'></ul>
                      <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>

                        <tbody id='EgiPq'></tbody>

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