2011-08-23 12 views
6

nasıl kullanılır Uygulamanızda iki viewControllers var FirstViewController ve DetailViewController. Bir tablo hücresine dokunduğunuzda, DetailViewController'a gidin. DetailViewController'da düzenleme ve reforme eklemek istiyorum NSNotification Bu sorun için nasıl NSNotification kullanabilirim?NSNotification

İşte NSNotification Stuff

-(IBAction) save{ 
strSelectedText=theTextField.text; 

[NSNotificationCenter defaultCenter]; 
NSNotification* notification = [NSNotification notificationWithName:@"MyNotification" object:self]; 
[[NSNotificationCenter defaultCenter] postNotification:notification]; 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (objFirstViewController) name:@"MyNotification" object:nil]; 



[self.navigationController popViewControllerAnimated:YES]; 
} 
+0

Size http://mac-objective-c.blogspot.com/2009/02/nsnotifications-broadcasting-mechanism.html – Tendulkar

+0

Bu yararlı olabilir bir bildirim için bir görev değildir. Sadece TableViewProgrammingGuide bir göz atın. Buradan başlayabilirsiniz: http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/TableView/Introduction/Introduction.html HTH –

+0

Önerirseniz, bildirim yerine delege desenini kullanmanız daha iyi olur. –

cevap

9
-(void)viewDidLoad { 

[NSNotificationCenter defaultCenter]; 
NSNotification* notification = [NSNotification notificationWithName:@"MyNotification" object:self]; 
[[NSNotificationCenter defaultCenter] postNotification:notification]; 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (objFirstViewController) name:@"MyNotification" object:nil]; 

} 


-(IBAction) save{ 

[[NSNotificationCenter defaultCenter] postNotificationName:MyNotification object:sender]; 

//this will go to where you implement your selector objFirstViewController. 

} 

-(void)objFirstViewController:(NSNotification *)notification { 

} 
0

yazı detailViewController bildirim uygulamak ve gözlemci olarak firstViewController eklemek istediğiniz bir yöntem.

fireViewController öğesini viewDidUnload'dan gelen gözlemci listesinden kaldırdığınızdan emin olun.

Şu anda detailViewController'ı gözlemci olarak ekliyorsunuz.

İlgili konular