第一个警报的按钮执行第二个警报,这基本上是给某人打电话的确认。我没有收到任何错误,但它不起作用 当我按下第二个警报时,呼叫按钮会崩溃
-(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/..../"]];
}
}
}
答案 0 :(得分:1)
您已分配在第二个警报视图中委派为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/..../"]];
}
}
我认为这会对你有所帮助。
答案 1 :(得分:0)
延迟启动第二个警报。问题是 - 警报需要一些时间来隐藏自己,在任何新警报出现之前,因此直接调用第二个警报将无效。
试试这个例子:
- (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:
值。
答案 2 :(得分:0)
答案 3 :(得分:0)
使用alertView:didDismissWithButtonIndex:
委托方法代替alertView:clickedButtonAtIndex:
委托方法。警报消失后调用前者。当您想要根据第一个警报视图的点按按钮显示秒时,这会更有意义。
还为UIAlertview对象提供标记。