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

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

        <legend id='kX6K5'><style id='kX6K5'><dir id='kX6K5'><q id='kX6K5'></q></dir></style></legend>

        在 Objective-C 中实现委托模式

        时间:2023-09-12

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

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

              <tfoot id='Wl1LF'></tfoot>

              • <bdo id='Wl1LF'></bdo><ul id='Wl1LF'></ul>
                    <tbody id='Wl1LF'></tbody>

                • 本文介绍了在 Objective-C 中实现委托模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在构建一个处理 NSURLConnection 请求的类.为了允许其他类使用这个类,我想允许主类在触发 connectionDidFinishLoading 时调用委托.

                  I am building a class that handles NSURLConnection requests. To allow other classes to use this class, I would like to allow the main class to call a delegate when connectionDidFinishLoading is fired.

                  我查看了很多文档,但找不到任何提供任何明确示例的内容,并且我拥有的代码由于某种原因没有调用委托.我到目前为止的代码是(代码不相关已删除):

                  I've looked through lots of documentation, but I can't find anything that gives any clear examples, and the code that I have doesn't call the delegate for some reason. The code I have so far is (code not relevant removed):

                  界面:

                  @interface PDUrlHandler : NSObject {
                  id delegate;
                  }
                  - (void)searchForItemNamed:(NSString *)searchQuery;
                  @property (nonatomic, assign) id delegate;
                  @end
                  @interface NSObject (PDUrlHandlerDelegate) 
                  - (void)urlHandler:(PDUrlhandler*)urlHandler searchResultsFinishedLoading:(NSDictionary *)resultData;
                  @end
                  

                  实施:

                  - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
                      NSLog(@"Fininshed Loading...");
                      resultData = [self parseJSON:jsonData];
                  
                      if(delegate && [delegate respondsToSelector:@selector(urlHandler:searchResultsFinishedLoading:)]) {
                          NSLog(@"Delegating!");
                          [delegate urlHandler:self searchResultsFinishedLoading:resultData];
                      } else {
                          NSLog(@"Not Delegating. I dont know why.");
                      }   
                  
                  }
                  

                  另一个类中的委托:

                  - (void)urlHandler:(PDUrlhandler*)urlHandler searchResultsFinishedLoading:(NSDictionary *)resultData;
                  {
                      NSLog(@"Delegating!!!!");
                  }
                  

                  推荐答案

                  原来我忘记设置委托了:

                  Turns out I forgot to set the delegate:

                  [currentHandler setDelegate:self];
                  

                  需要在对 PDUrlHandler 进行初始调用的行之后.

                  needed to go after the line that makes the initial call to the PDUrlHandler.

                  这篇关于在 Objective-C 中实现委托模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Android:一旦 webview 完成滚动,就使按钮可见 下一篇:QuickLook 消费者作为 NSViewController 的代表

                  相关文章

                    <bdo id='r0XtN'></bdo><ul id='r0XtN'></ul>

                    1. <tfoot id='r0XtN'></tfoot>

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

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