Cocoa Touch Design Pattern - delegation(未完待续)

注:本文是一份学习笔记。

cocoa touch由苹果公司提供的软件开发api, 用于开发 iphone\ipod\ipad上的软件。也是苹果公司针对iPhone应用程序快速开发提供的一个类库。此库以一系列框架库的形式存在,支持开发人员使用用户界面元素构建图像化的事件驱动的应用程序。
Cocoa Touch 层由多个框架组成,他们为应用程序提供了核心功能。
  UIKit 负责启动和结束应用程序,控制界面和多触点事件
  Map Kit 提供地图的相关服务
  Game Kit 创建和使用网络机制
  Message UI/Adress Book UI 提供操作电子邮件和联系人的信息

 

A callback is a function that is triggered when an event occurs. Usually, this is an event that happens in response to user input. We don’t exactly know when this event might occur, but we set up
a callback so that when it does occur, our code will be called. In some systems, callbacks are sent to objects that are known as listeners.

In Cocoa Touch, callbacks are implemented using a technique known as delegation.

 

There are two basic categories of delegate methods. Some are “for-your- information” methods. These methods are sent to a delegate to inform it that something has happened. For example, you would implement textViewDidChange: to be informed when the text in a UITextView changes.

Other delegate methods are “what-should-I-do?” methods. These methods expect a response back from the delegate that will dictate the behavior of the delegating object. For example, if a delegate implements textView:shouldChangeTextInRa nge:replacementText:, it can prevent an inappropriate edit by returning NO.

 

(Here’s a shortcut: in Xcode, hold down the Option and Command keys and double-click the name of the protocol. The documentation browser will appear displaying a list of every method for that protocol.)

 

A framework is a collection of related classes, and Cocoa Touch is a set of frameworks.

 

Add frameworks to your project:

Select Edit Active Target from the Project menu. In the Target Info window that appears, select the General tab. At the bottom of the window is a list of Linked Libraries. Click the + button on the bottom-left corner of the window. A sheet will drop down from this window listing all of the available frameworks for iPhone OS.

 

Location Services enables applications to determine the device’s geographical location. Core Location is the framework that you use to talk to Location Services. No matter what type of device is being used, the Core Location code you write does not change.

 

Most of the applications in this book have controller objects that exist the entire time an application is running. This is the behavior for many controller objects in real applications for two reasons:
• Controller objects are the brains of an application. They take on a lot of roles and typically are needed throughout the execution of an application.
• Controller objects do not consume a lot of memory themselves. They only hold pointers to view and model objects, which are the two types of classes that consume the majority of memory. If memory is running low, the controller can get rid of the big objects it has pointers to (and, ideally, be able to reload those objects when needed).

 

Now, this isn’t to say that all controller objects exist throughout an application’s lifetime. Some controller objects can exist temporarily for a specific task. In these circumstances, you will need to release the appropriate instance variables in the controller’s dealloc method.

 

The Core Location framework tells us where we are in the world; the MapKit framework shows us that world.

 

 






 

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值