0

こんにちは、アプリの delegate.m のメソッドに nsnotifiaction を割り当て、このメソッドは 30 秒ごとに eprox を呼び出します。viewcontroller と execute メソッドでその通知が必要です。これが appdelegate .m の私のコードです。

- (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で

//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];
}

その方法は..

- (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ファイルで読み込まれている間、超過したメソッドの応答がありません。

私を助けてください。

4

2 に答える 2

4

タイプミスがあります。

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

//Your error here-------------------------------------------------------------------------------------------------------------------------------------^

そこにスペースを入れました。

SideNote:すべての通知名について、別のファイルを作成し、すべての通知名を定数文字列として配置する必要があります/できます。

const NSString *kBannerViewActionWillBegin=@"BannerViewActionWillBegin";

これにより、値を変更しやすくなり、そのようなタイプミスが発生しなくなります。

于 2013-04-08T06:31:16.210 に答える
0

あなたのコードから、通知名を除いて、他のすべてのものは問題ありません。通知が発生するかどうかを確認しましたか。ブレークポイントを通知発火ラインに置いてみてください。

于 2013-04-08T06:37:49.743 に答える