Teddy13
Teddy13

Reputation: 3854

calling a method from UITextLabel

I have a method called -(IBAction)setPicker:(id) sender

Basically this method substitutes a keyboard into a datePicker when called upon. I want this to happen (aka the method setPicker to be called) as soon as the user touches the text field trying to input something. The problem is that no matter what event I link it too, it does not end up calling the method.

I tried connecting the text field to the event "touch up inside" (thought I could do it the same way as I would for a button but no luck).

Does anyone have any suggestions or ideas on how this can be done?

Thanks!

Upvotes: 0

Views: 220

Answers (4)

mAc
mAc

Reputation: 2514

Have you set the Delegate to your Textfield..

textField.delegate = self;

I have just use this method to do the same :-

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    return NO;
}

Hope it helps you..

Upvotes: 0

Aliaksandr Andrashuk
Aliaksandr Andrashuk

Reputation: 965

If you want show UIDatePicker (or any other view) instead of keyboard when editing UITextField, you can do following:

UITextField* textField = ...; // your textfield
UIDatePicker* picker = ...; //your picker (or any other view)

textField.inputView = picker;

Upvotes: 0

Ilanchezhian
Ilanchezhian

Reputation: 17478

Implement UITextFieldDelegate.

Implement the method

- (void)textFieldDidBeginEditing:(UITextField *)textField

from UITextFieldDelegate.

Show your datepicker when this delegate method get called.

Upvotes: 1

Tendulkar
Tendulkar

Reputation: 5540

There is a delegate method for the UITextField .

(i.e `- (void)textFieldDidBeginEditing:(UITextField *)textField)`

Upvotes: 0

Related Questions