第一个警报中的一个按钮执行第二个警报,这基本上是对呼叫某人的确认。我没有得到任何错误,但它不工作。
当我按下第二个警报时,呼叫按钮就会崩溃
-(void) alertView: (UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *buttonString = [alertView buttonTitleAtIndex:buttonIndex];
if ([buttonString isEqualToString:@"Phone"])
{
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Notice!" message:@"You are about to call .... Do you wish to continue?" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Call", nil];
[alert2 show];
if ([buttonString isEqualToString:@"Call"]){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://12345678"]]];
}
if([buttonString isEqualToString:@"Website"]){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"website"]];
}
if ([buttonString isEqualToString:@"Facebook"]){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.facebook.com/groups/..../"]];
}
}
}发布于 2012-07-30 20:13:04
您在第二个警报视图中将委派分配为nil。这就是第二次不调用alertView:clickedButtonAtIndex:委托方法的原因。所以你应该将委托赋值为self。
-(void) alertView: (UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *buttonString = [alertView buttonTitleAtIndex:buttonIndex];
if([buttonString isEqualToString:@"Phone"]) {
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Notice!" message:@"You are about to call .... Do you wish to continue?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Call", nil];
[alert2 show];
}
if([buttonString isEqualToString:@"Call"]){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://12345678"]]];
}
if([buttonString isEqualToString:@"Website"]){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"website"]];
}
if([buttonString isEqualToString:@"Facebook"]){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.facebook.com/groups/..../"]];
}
}我想这对你会有帮助的。
发布于 2012-07-30 19:47:09
延迟启动第二个警报。问题是- alert需要一段时间来隐藏自己,然后才能出现任何新的警报,因此直接调用第二个警报将不起作用。
例如,请尝试执行以下操作:
- (void) alertView: (UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *buttonString = [alertView buttonTitleAtIndex:buttonIndex];
if ([buttonString isEqualToString:@"Phone"])
{
[self performSelector:@selector(callSecondAlertView) withObject:nil afterDelay:1];
}
}
- (void)callSecondAlertView
{
//show new alert view
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Notice!" message:@"You are about to call .... Do you wish to continue?" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Call", nil];
[alert2 show];
[alert2 release];
}如果不工作,或者延迟太长-使用afterDelay:值播放。
发布于 2012-08-09 13:40:30
明白了!由于某种原因,[[alertView subviews objectAtIndex:6] setBackgroundColor...对于第一个alertView按钮,我有干扰第二个alertView功能。但是,直到我将xcode更新到4.4.1之后,xcode才直接指向这个问题
https://stackoverflow.com/questions/11720795
复制相似问题