3

アプリに Tapjoy を使用しようとしており、次のコードを使用しています

-(void)getTapJoyAd{
    [Tapjoy getFullScreenAd];

    // A notification method must be set to retrieve the fullscreen ad object.
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(getFullScreenAd:)
                                                 name:TJC_FULL_SCREEN_AD_RESPONSE_NOTIFICATION
                                               object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(fullscreenAdClosed:)
                                                 name:TJC_VIEW_CLOSED_NOTIFICATION
                                               object:nil];

    // This method requests the tapjoy server for current virtual currency of the user.
    [Tapjoy getTapPoints];
    // A notification method must be set to retrieve the points.
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getUpdatedPoints:) name:TJC_TAP_POINTS_RESPONSE_NOTIFICATION object:nil];
}

問題は、メソッドをもう一度思い出すと、2 つの画面が一緒に開くことです..このメソッドを呼び出すほど、より多くの画面が開きます..

4

1 に答える 1

3

基本的に問題は、何回notification観測されてからメソッドが実行されているかです。したがって、問題を防ぐことができる1つの方法notificationは、投稿されて観察されたら削除することnotification observerです. また、部分をどのように扱っているかは、コードにも依存しますnotification。したがってremove observer、以下を確認してみてください:-

-(void)viewDidDisappear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:TJC_FULL_SCREEN_AD_RESPONSE_NOTIFICATION object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:TJC_VIEW_CLOSED_NOTIFICATION object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:TJC_TAP_POINTS_RESPONSE_NOTIFICATION object:nil];
}
于 2013-12-23T07:07:39.957 に答える