無論如何可以觀察是否顯示UIAlertView並在調用時調用函數。如何觀察UIAlertView何時顯示?
不被創建的UIAlertView中和,我想一個函數中調用同一個類中顯示。
它很難解釋,但簡單地說,我需要以某種方式監控或觀察,如果角度的就像第一響應者或某事,因爲我不認爲有可能監視是否顯示UIAlertView:/
無論如何可以觀察是否顯示UIAlertView並在調用時調用函數。如何觀察UIAlertView何時顯示?
不被創建的UIAlertView中和,我想一個函數中調用同一個類中顯示。
它很難解釋,但簡單地說,我需要以某種方式監控或觀察,如果角度的就像第一響應者或某事,因爲我不認爲有可能監視是否顯示UIAlertView:/
聽起來像一個通知的工作。
說A類創建UIAlert,B類需要觀察它。 A類定義了一個通知。 B類註冊該通知。當A類打開警報時,會發布通知,而B類會自動看到它。
有關詳細信息,請參閱NSNotification。
可以這樣做(如果您不想執行事件或生成通知,只想檢查是否顯示警報),則將alertview聲明爲類級變量並在發佈時釋放它你的alertview被解僱了。
@interface ViewControllerA:UIViewController{
UIAlertView *theAlertView;
}
@property (nonatomic, retain) UIAlertView *theAlertView;
@end
@implementation ViewControllerA
@synthesize theAlertView;
- (void)showAlertView{
// theAlertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
// [theAlertview show];
self.theAlertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[self.theAlertview show];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
// [theAlerView release];
self.theAlertView=nil; // The synthesized accessor will handle releasing.
}
現在,你可以通過檢查:
if(viewControllerAClassObj.theAlertView){
}
希望這有助於
感謝,
Madhup
你應該參照屬性時使用'self'符號你不應該在'dealloc'中釋放一個屬性。看我的編輯。你原來的方式是脆弱的,並要求麻煩。 – TechZen 2010-04-08 14:06:58
這是一個很好的解決方案,但我必須像每秒運行一次,我可以以某種方式* Observer *那個變量? – DotSlashSlash 2010-04-08 15:40:49