2013-04-08 69 views
0
接收

你好,我在指定應用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文件中讀取方法時,我沒有得到多餘的方法的響應。

請幫幫我。

+0

在applegate顯示一個alertview,每當你收到一個警報,並使該alertview子視窗,使我們會得到警報各自的視圖 – 2013-04-08 06:41:17

回答

4

您有一個錯字錯誤。

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

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

您已在此放置空間。

附註:對於所有的通知名稱,您應該/可以創建一個單獨的文件並將所有通知名稱都設置爲常量字符串。

const NSString *[email protected]"BannerViewActionWillBegin"; 

這將更容易改變的價值,沒有這樣的錯字會發生。

+0

非常感謝你,小錯誤創建大頭痛.i像你的建議和答案非常很多。 – user2256034 2013-04-08 06:46:07

+0

這就是我從SO學到的東西。感謝我在這裏沒有見過的教師。 – 2013-04-08 06:51:51

0

從你的代碼中,我得到的是通知名稱的所有其他東西除外是好的,你檢查通知是否被解僱。嘗試在通知點擊線上保留斷點。

相關問題