views:

107

answers:

3

Hello community, 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?

my greetings to all helpers!

+5  A: 

Tapping a text field should never result in some action. In my opinion that is bad user interface design. Why don't you add a button next to the field that runs the above code?

St3fan
+2  A: 

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 UITextFieldDelegate protocol and watch for textFieldShouldBeginEditing:. 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 (leftView or rightView; read the docs on the correct UE for these).

You could subclass UITextField to override touchesBegan:withEvent, touchesEnded:withEvent: and touchesCancelled:withEvent: to handle the touch yourself. Remember: you must receive a touchesBegan and touchesEnded without a touchesCancelled between them in order to consider it a touch. Never fire an action based only on touchesBegan.

Rob Napier
A: 

Hello you two,

thank you for your good help, i listened to you and implemented an UIButton, it is very easier to make an event from it.

Thank you for helping me

Marco
Please select one of the two posts above as the "Correct" answer. You can upvote one or both too. And then delete this "answer" as it is not an answer. That is just so we keep StackOverflow nice and tidy.
mahboudz