NSNotification不视图控制器从的appDelegate
你好,我在指定应用delegate.m的方法nsnotifiaction这个方法调用eprox每30秒,我想在视图 - 控制其notifcation ADN执行方法, 这里是我的appdelegate .MNSNotification不视图控制器从的appDelegate
的代码- (void)layoutAnimated:(BOOL)animated{
BOOL yy= self.bannerView.bannerLoaded;
if (yy==1){
self.iAdString=[NSMutableString stringWithString:@"1"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"BannerViewActionWillBegin" object:self];
}
else{
self.iAdString=[NSMutableString stringWithString:@"0"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"BannerViewActionDidFinish" object:self];
}
}
和viewcontroller.m
// i的viewDidLoad方法定义
- (void)viewDidLoad{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willBeginBannerViewActionNotification:) name:@"BannerViewActionWillBegin "object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishBannerViewActionNotification:) name:@"BannerViewActionDidFinish" object:nil];
}
其方法是1..
- (void)willBeginBannerViewActionNotification:(NSNotification *)notification{
[self.view addSubview:self.app.bannerView];
NSLog(@"come");
}
- (void)didFinishBannerViewActionNotification:(NSNotification *)notification {
NSLog(@"come");
[self.app.bannerView removeFromSuperview];
}
- (void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
在appdelegate文件中读取方法时,我没有得到多余的方法的响应。
请帮帮我。
您有一个错字错误。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willBeginBannerViewActionNotification:) name:@"BannerViewActionWillBegin "object:nil];
//Your error here-------------------------------------------------------------------------------------------------------------------------------------^
您已在此放置空间。
附注:对于所有的通知名称,您应该/可以创建一个单独的文件并将所有通知名称都设置为常量字符串。
const NSString *[email protected]"BannerViewActionWillBegin";
这将更容易改变的价值,没有这样的错字会发生。
非常感谢你,小错误创建大头痛.i像你的建议和答案非常很多。 – user2256034 2013-04-08 06:46:07
这就是我从SO学到的东西。感谢我在这里没有见过的教师。 – 2013-04-08 06:51:51
从你的代码中,我得到的是通知名称的所有其他东西除外是好的,你检查通知是否被解雇。尝试在通知点击线上保留断点。
在applegate显示一个alertview,每当你收到一个警报,并使该alertview子视窗,使我们会得到警报各自的视图 – 2013-04-08 06:41:17