0

是否有可能观察是否正在显示 UIAlertView 并在显示时调用函数。

UIAlertView 没有在我想要调用函数的同一个类中创建和显示。

很难解释,但简单地说,我需要以某种方式监视或观察视图是否变得像第一响应者或其他东西,因为我认为无法监视 UIAlertView 是否正在显示:/

4

2 回答 2

3

听起来像是通知的工作。

假设 A 类创建了 UIAlert,B 类需要观察它。A 类定义了一个通知。B 类注册该通知。当 A 类打开警报时,它会发布通知,B 类会自动看到它。

有关详细信息,请参阅 NSNotification。

于 2010-04-08T13:09:07.173 回答
0

您可以这样做(如果您不想执行事件或生成通知并且只想检查是否显示警报),将警报视图声明为类级别变量并在警报视图被解除时释放它.

@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){

}  

希望这可以帮助,

谢谢,

马杜普

于 2010-04-08T13:30:28.240 回答