什么是“代表"?在 Objective C 的 iPhone 开发中? [英] What is a "delegate" in Objective C's iPhone development?

查看:18
本文介绍了什么是“代表"?在 Objective C 的 iPhone 开发中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Objective C 的 iPhone 开发中的委托"是什么?

What is a "delegate" in Objective C's iPhone development?

推荐答案

查看此讨论

委托允许一个对象在事件发生时向另一个对象发送消息.例如,如果您使用 NSURLConnection 类从网站异步下载数据.NSURLConnection 有三个常见的委托:

A delegate allows one object to send messages to another object when an event happens. For example, if you're downloading data from a web site asynchronously using the NSURLConnection class. NSURLConnection has three common delegates:

 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
 - (void)connectionDidFinishLoading:(NSURLConnection *)connection
 - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

当 NSURLConnection 遇到失败、成功完成或收到来自网站的响应时,将分别调用这些委托中的一个或多个.

One or more of these delegates will get called when NSURLConnection encounters a failure, finishes successfully, or received a response from the web site, respectively.

这篇关于什么是“代表"?在 Objective C 的 iPhone 开发中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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