我正在尝试在我的Storyboard
.
当我不使用情节提要时,此代码有效。
这是在 ViewController1 中:
- (IBAction) buttonClickedListener2:(id)sender {
[[NSNotificationCenter defaultCenter]
postNotificationName:@"TestNotification"
object:self];
}
这是在 ViewController2 中:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveTestNotification:)
name:@"TestNotification"
object:nil];
NSLog(@"initWithNib");
}
return self;
}
- (void) receiveTestNotification:(NSNotification *) notification
{
// [notification name] should always be @"TestNotification"
// unless you use this method for observation of other notifications
// as well.
if ([[notification name] isEqualToString:@"TestNotification"])
NSLog (@"Successfully received the test notification!");
}
代码有什么问题吗?正如我所说,我想让它在我的故事板中工作。
如果你能给我一些关于如何在STORYBOARD
.