i have a problem.
I have implemented an UITextField that contains a phonenumber, then i have implemented the following method to call the phone number:
- (void)rufeAn{
NSString *prefix = (@"tel://");
UIApplication *app = [UIApplication sharedApplication];
NSString *dialThis = [NSString stringWithFormat:@"%@%@", prefix, map.kordinate.telefon];
NSURL *url = [NSURL URLWithString:dialThis];
[app openURL:url];
}
But how can i say to the textField when i touch on it, to start the method and dial?
I agree with St3fan that an normal TextField should never cause an action by tapping. I will assume for the moment that you have a special UITextField that can be made uneditable and then looks like a
UILabel, formatted to look like a hyperlink. Such a UI could be correct. Tapping a text field that looks like it’s editable but actually makes a phone call would of course be incorrect.You could implement the
UITextFieldDelegateprotocol and watch fortextFieldShouldBeginEditing:. Since this text field is not editable, obviously you should return NO.You could add a “call” button inside of the text field using its overlay views (
leftVieworrightView; read the docs on the correct UE for these).You could subclass
UITextFieldto overridetouchesBegan:withEvent,touchesEnded:withEvent:andtouchesCancelled:withEvent:to handle the touch yourself. Remember: you must receive atouchesBeganandtouchesEndedwithout atouchesCancelledbetween them in order to consider it a touch. Never fire an action based only ontouchesBegan.