Iphone 2.一个接一个地查看
我按下按钮时会显示一个UI2警报。我希望第二个警报仅在第一个UIAlert被解除时可见,即当我们按下第一个OK按钮时 请问我该如何进行?下面是我的代码:Iphone 2.一个接一个地查看,iphone,ipad,uialertview,Iphone,Ipad,Uialertview,我按下按钮时会显示一个UI2警报。我希望第二个警报仅在第一个UIAlert被解除时可见,即当我们按下第一个OK按钮时 请问我该如何进行?下面是我的代码: - (IBAction)button:(id)sender { UIAlertView *view; view = [[UIAlertView alloc] initWithTitle: @"Message" message: @"Adding..." delegate: self cancelButtonTitle
- (IBAction)button:(id)sender {
UIAlertView *view;
view = [[UIAlertView alloc]
initWithTitle: @"Message"
message: @"Adding..."
delegate: self
cancelButtonTitle: @"OK" otherButtonTitles: nil];
[view show];
MyAppAppDelegate *appDelegate = (MyAppAppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDelegate.array_presets.count) {
view = [[UIAlertView alloc]
initWithTitle: @"Message"
message: @"limit already reached"
delegate: self
cancelButtonTitle: @"OK" otherButtonTitles: nil];
[view show];
}
[view autorelease];
}
对两个警报视图使用不同的标记
alertView.tag = 1000;
实现警报视图委托方法并检查标记值。使用第一个警报视图调用代理时,创建并显示第二个警报视图
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(alertView.tag == 1000)
{
//first alert view's button clicked
UIAlertView *view = [[UIAlertView alloc]
initWithTitle: @"Message"
message: @"limit already reached"
delegate: self
cancelButtonTitle: @"OK" otherButtonTitles: nil];
view.tag = 2000;
[view show];
}
if(alertView.tag == 2000)
{
//handle second alert view's button action
}
}
您可能打算在第二个“if”中使用
if(alertView.tag!=1000)
,或者检查另一个值,如1001。但我认为这并不能解决海报的问题。谢谢你的纠正。编辑了答案中的代码。我认为这应该可以解决问题,因为他想在第一个警告被取消后显示第二个警告视图。