Mac 이나 iPhone에서 오브젝트간 메세지를 전달하는 방법은 3가지가 있다.

1. Notifications

1. 원리
object가 notification center에 message를 보내면 notification center에 등록된 selector로 해당 메세지를 보내준다.

2. 장단점
다른 object도 해당 message를 볼 수 있다. 즉, 정보를 얻을 수가 있다.
오브젝트간 1:다 관계를 형성할 수 있다.

3. 관련 클래스
NSNotificationCenter

4. 사용법
* 메세제를 받을 수 있도록 설정
[[NSNotificationCenter defaultCenter] addObserver:self selector:@(action:)];

* 센터에 메세지 보내기
[[NSNotificationCenter defaultCenter] postNotificationName:@"MessageName" object:self];


2. Delegates


1. 원리
object와 object의 1:1 관계를 정의하는 패턴이다.

2. 장단점
미리 정의할 수 있는 특정 기능을 수행해야 할 경우에 유용하다. 함수를 호출하는 방식으로 실행된다.


3. Target-Action


1. 예
버튼

2. 사용법

id target = ...; // defined elsewhere

SEL action = ...' // defined elsewhere


[target performSelector:action];

[fileDownloader downloadFile:(NSURL*)url target:(id)target didSucceed:(SEL)succeed didFail:(SEL)failed];


Ref URL
2011/01/17 21:34 2011/01/17 21:34
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://jams.pe.kr/rss/response/22

댓글+트랙백 ATOM :: http://jams.pe.kr/atom/response/22

트랙백 주소 :: 이 글에는 트랙백을 보낼 수 없습니다

트랙백 RSS :: http://jams.pe.kr/rss/trackback/22

트랙백 ATOM :: http://jams.pe.kr/atom/trackback/22