IOS Dev Intro - Protocols and Delegate

103 篇文章 0 订阅


Excerpt from Beginning IOS Programming by Nick Harris


protocols and Delegates


Model-View-Controller is a great high-level programming pattern, 
but to use it in a programming language, you need the tools to 
make it work. Objective-C has these tools. The model layer
is implemented using classes and properties to create reusable 
objects. The view layer is implemented in the Cocoa and Cocoa 
Touch APIs, including reusable views and subviews such as buttons 
and text fields. The controller layer is done by using delegates 
and data sources to facilitate the communication.


Delegates and data sources are used heavily in Objective-C. It’s 
a way of having one part of the software ask for work to be done 
by another part. This fits the MVC design pattern with the 
communication between views and controllers. Because views interact 
only with controllers and never with the model, they need a way of 
asking for model data from the controller. This is the role of the 
data source. When a user interacts with a view, the view needs to 
tell the controller about it. Delegates are used for this role. 
Typically, your controller will perform both of these roles.


A view needs to define all the questions it may ask its data source 
and what type of answer it expects in return. It also needs to 
define all the tasks it may ask the delegate to perform in response 
to user interaction. In Objective-C this is done through protocols. 
You can think of a protocol as a contract between the view and its 
data source or delegate.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值