1

I have a UIControl within a UIScrollView. I scrollview has a textfield. I want the text field to loose focus when the UIControl is touched.

This is the method the UIControl is hooked up to:

- (IBAction) clickedBackground
{
    [self.view endEditing:YES]; //make the view end editing!

}

But, the UIControl doesn't seem to call this event when touched. I did try this as suggested elsewhere, but to no avail:

[scroller setDelaysContentTouches:YES];
Zaxter
  • 2,939
  • 3
  • 31
  • 48

1 Answers1

2

The touch event on your UIControl is getting conflicted with touch event of your UIScrollView.

If you just to loose focus of the text field you can use on a button tap.

[textField resignFirstResponder];

But ideal way is to loose focus when user taps anywhere outside the text field. This answer would help you to achieve this.

However, if you just want to resign the keyboard. Then make use of resignFirstResponder on a button tap. You can also look into UITextField input accessory view in order to display a button on the keyboard input view that user can tap on.

Community
  • 1
  • 1
Subhransu
  • 108
  • 4
  • Thanks! I ended up using "scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;" from the link you provided. – Zaxter Jul 16 '14 at 12:18