블로그 이미지
Sunny's

calendar

1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

Notice

2012. 3. 28. 21:03 IPhone

 

 

전달 받을 컨트롤러 에서 NotificationCenter에 옵져버 등록 한다.

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(myFunction:) name:@"msgName" object:nil];


myFunction 함수 구현도 필요
-(void) myFunction:(NSNotification *) note {
[[note userInfo] objectForKey:@"myKey"]; // 메시지의 내의 myKey 라는 값을 가져온다.
}


통지를 보내는 쪽 에서 처리
// myKey라는 키로 value 라는 문자열을 전달 한다.
NSDictionary *dic = [NSDictionary dictionaryWithOjbect:@"value" forKey:@"myKey"];

NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:@"msgName" object:self userInfo:dic];


통지를 보내면 통지를 등록한 컨트롤로에 정의된 myFunction 함수가 호출된다.

◆ 데이터 여러개 보낼때
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:EDIT_MAIN_TABLE], @"type",[NSNumber numberWithBool:YES], @"edit", nil];

◆ 데이터 하나만 보낼때
NSDictionary *dic = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:CARD_TYPE_MEMBERSHIP] forKey:@"type"];

출처 : http://comxp.tistory.com/188 


posted by Sunny's