에 대한 자세한 내용은
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(getData:)
notificationName:@"Data"
object:nil];
- getData:(NSNotification *)notification {
NSString *tappedIndex = [[_notification userInfo] objectForKey:@"KEY"];
}
아래와 같이 같은 앱 위임에
첫째
후 알림 :
NSDictionary *_dictionary=[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSString stringWithFormat:@"%d",newIndex],nil] forKeys:[NSArray arrayWithObjects:SELECTED_INDEX,nil]];
[[NSNotificationCenter defaultCenter] postNotificationName:SELECT_INDEX_NOTIFICATION object:nil userInfo:_dictionary];
다음 원하는의 ViewController를 등록 이 알림을 다음과 같이 확인하십시오 :
/***** To register and unregister for notification on recieving messages *****/
- (void)registerForNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yourCustomMethod:)
name:SELECT_INDEX_NOTIFICATION object:nil];
}
/*** Your custom method called on notification ***/
-(void)yourCustomMethod:(NSNotification*)_notification
{
[[self navigationController] popToRootViewControllerAnimated:YES];
NSString *selectedIndex=[[_notification userInfo] objectForKey:SELECTED_INDEX];
NSLog(@"selectedIndex : %@",selectedIndex);
}
호출이 등의 viewDidLoad 메서드 :
- (void)viewDidLoad
{
[self registerForNotifications];
}
다음 언로드에이 메서드를 호출하여이 관찰자를 제거 :
-(void)unregisterForNotifications
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:SELECT_INDEX_NOTIFICATION object:nil];
}
-(void)viewDidUnload
{
[self unregisterForNotifications];
}
은 당신을 도움이되기를 바랍니다.
내가이 코드를 삽입해야 안녕하세요 : [[NSNotificationCenter defaultCenter] addObserver : 자기 선택 : @selector (GetData의 : notificationName : "데이터"@ 개체 : yourdata] – Marv
viewDidLoad로 호출 할 수있는 것처럼 알림 데이터를 확인하려는 경우 – Buntylm
viewData에서 yourData를 어떻게 객체로 가져올 수 있습니까? –