问题
I have a view on map with a button and a label on the button. On the label i have phone number that comes from a plist. The variable of the phone number in the plist called "storePhone" and i implemented it in this way:
text4.text = myAnn.storePhone;
I made this method for pressing the button and opening the phone.app for dialing the number. Everything works great but i want a UIViewAlert to say to the user something like:"your going to dial this number, are you sure?" before the phone.app is open.
How can i do that?
This is my button methode:
-(IBAction)callToStore
{
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", text4.text]];
[[UIApplication sharedApplication] openURL:url];
}
Thanks.
回答1:
I did it.
This is how you do it:
- (IBAction)moreInfoViewAlert:(id)sender
{
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"חיוג לסניף"
message:@"הנך עומד/ת לבצע חיוג, האם את/ה בטוח?"
delegate:self
cancelButtonTitle:@"ביטול"
otherButtonTitles:@"חיוג", nil];
[message show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"חיוג"])
{
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", text4.text]];
[[UIApplication sharedApplication] openURL:url];
}
}
Attach the IBAction method to your button and you're good to go.
来源:https://stackoverflow.com/questions/8478198/display-uialertview-before-opening-phone-app