1

I'm trying to end editing a UITextView when I click a UIControl on another cell.

If I tap on a cell containing the UIControl, the text view ends editing, as expected. However, when I tap on say, a UIStepper, the control responds fine but the text view continues in edit mode.

What mechanism would allow me to "catch" the tap anywhere outside the text view and allow me to exit edit mode? Thanks for the help.

titusmagnus
  • 2,014
  • 3
  • 23
  • 23

1 Answers1

2

You can use endEditing: method:

[self.view endEditing:YES];

In Swift:

self.view.endEditing(true)
Stan James
  • 2,535
  • 1
  • 28
  • 35
Alex Kosyakov
  • 2,095
  • 1
  • 17
  • 25
  • Where would you place this statement? I don't seem to be triggering any outgoing event when I tap the control. Thanks. – titusmagnus May 15 '16 at 22:12
  • 1
    @titusmagnus UIStepper is a UIControl. Add a target for the "ValueChanged" event. – rmaddy May 15 '16 at 22:16
  • @rmaddy I know. My UITableView has quite a few cells with UIControls. Having to set them up like you suggest seems a bit overkill. Isn't there a more global way to catch this event and call endEditing:? – titusmagnus May 15 '16 at 22:19
  • @titusmagnus Nope. You need to handle every case the way you want to. There's no "global" way because everyone might want different behavior. – rmaddy May 15 '16 at 22:22
  • That's too bad. Oh well, I have update the code with a combination of two things: 1)` [cell.stepper addTarget:cell action:@selector(stepperValueDidChange) forControlEvents:UIControlEventValueChanged]; and 2) [self.tableView endEditing:YES]; Thanks for the help! – titusmagnus May 15 '16 at 22:34