问题理解委托模式& Objective C中的回调函数 [英] Problem understanding Delegating pattern & callback functions in Objective C

查看:155
本文介绍了问题理解委托模式& Objective C中的回调函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以简单地在目标C中解释委托模式和回调函数。
或者可以指向一些文档(使用简单和基本解释),这些可以使这些概念更清晰。因为我从任何书籍或网站或(Apple开发人员)的参考资料中都没有了解它。

Can anyone simply explain delegating pattern and callback function in objective C. Or can point to some documents (with Easy and Basic Explanation) which can make these concepts clearer to me. As i am not getting any idea about it from any book or website or (Apple Developer)references.

我所了解的所有资源都让我更加了解通过使用我觉得难以消化的术语来混淆。

All the resources i have come across to understand this, makes me more confuse by using the terminology which i find hard to digest.

感谢任何帮助。

推荐答案


委托 名词| deligit |

发送的人或授权代表他人,特别是发送给会议的
当选代表。

A person sent or authorized to represent others, in particular an elected representative sent to a conference.

Cocoa Touch框架中的代表例如Foundation或UIKit是一个单独的对象实例,它被委托监听,并可选择代表委托者决定行为。

A delegate in the Cocoa Touch frameworks such as Foundation or UIKit is a separate object instance that is entrusted to listen in to, and optionally decide behaviours on behalf of the delegator.

以<$ c为例$ C>的UIWebView 。只要该实例符合 UIWebViewDelegate 协议,web视图就可以将责任委托给一个委托,即承诺在Web视图期望委托行为时表现出来

Take the example of UIWebView. The web view can entrust responsibility onto one delegate as long as that instance conforms to the UIWebViewDelegate protocol, that is promises to behave as the web view expects a delegate to behave.

委托不时被调用。嵌入在委托方法名称中的是有关呼叫内容的信息。

The delegate gets called from time to time. Embedded in the delegate method names is information about what the call is about.


  • webView: 应该 StartLoadWithRequest:navigationType: - 告诉代表webview想要加载请求,并询问代表是否 这样做。

  • webView: StartLoad: - 告知代表网页视图开始加载一个页面,做任何事都为时已晚(这是一个实际上不可用的假设方法,我用它作为一个一致的例子)

  • webView的: 确实 FinishLoad: - 告诉代表网页视图加载页面现在已经完成。

  • webView:shouldStartLoadWithRequest:navigationType: - Tells the delegate that the webview wants to load a request, and ask the delegate if it should do so.
  • webView:willStartLoad: - Tells the delegate that the web view will start loading a page, and it is too late to do anything (This is a hypothetical method that is not actually available, I use it as a consistent example).
  • webView:didFinishLoad: - Tells the delegate that the web view did load a page and it is now finished.

使用委托的价值在于你不需要子类 UIWebView 来调整它的行为方式。一个objkect也可以作为许多不同webview的委托,甚至可以作为许多不同类的代理。

The value of using delegation is that you do not need to sub-class UIWebView in order to tweak how it behaves. One objkect can also serve as delegate to many different webviews, or even serve as delegate to many different kinds of classes.

普通 UIViewController 子类可能符合许多委托协议,例如 UITableViewDelegate 来响应表中的选择, UIActionSheetDelegate 回应行动表中的选择等。

A normal UIViewController subclass probably conforms to many delegate protocols, for example UITableViewDelegate to respond to selections in a table, UIActionSheetDelegate to respond to selection from an action sheet, etc.

这篇关于问题理解委托模式&amp; Objective C中的回调函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆