問題,我希望我有一個人幫助我在這一個更好的運氣:與NSNotificationCenter和UIPickerView
我是用戶進行選擇一個UIPickerView,然後按下按鈕。我可以很高興地獲得用戶的選擇,如我的NSLog所示,並且完成後,我想向另一個視圖控制器發送通知,該視圖控制器將顯示帶有所選選項的標籤。那麼,儘管看起來一切都是正確的,但它不起作用並且標籤保持不變。下面是代碼:
播音員:
if ([song isEqualToString:@"Something"] && [style isEqualToString:@"Other thing"])
{
NSLog (@"%@, %@", one, two);
[[NSNotificationCenter defaultCenter] postNotificationName:@"Test1" object:nil];
ReceiverViewController *receiver = [self.storyboard instantiateViewControllerWithIdentifier:@"Receiver"];
[self presentModalViewController:receiver animated:YES];
}
觀察報:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotification) name:@"Test1" object:nil];
}
return self;
}
-(void)receiveNotification:(NSNotification*)notification
{
if ([[notification name] isEqualToString:@"Test1"])
{
[label setText:@"Success!"];
NSLog (@"Successfully received the test notification!");
}
else
{
label.text = @"Whatever...";
}
}