0

I know this question has been asked before but I couldn't find an answer that applied to my problem. I've got a UITableViewController that has a third row that is filled with a UITextView.

I'm quite happy with the way it looks and the way text is typed into it. However I'm unable to find a way of getting rid of the keyboard once the user is done entering text. I'd like to be able to use the return button for actual \n in the text.

I've gotten this far that pressing the upper two rows will make the textView te resignFirstTransponder but is there a way to catch a tap on the greyish background?

This is all in a UITableViewController loaded from a nib file. Btw, I'm quite new to iOS programming so the more elaborate your answer the better :)

Thanks!

Chris
  • 1

3 Answers3

1

A pattern many apps follow is to show a horizontal bar with buttons on it just above the keyboard. It can contain a done button clicking on which you can hide the keyboard. And of course you will have to create that horizontal view yourself.

Another way would be to enable a touch recognizer elsewhere, and on a tap outside hide the keyboard

aqs
  • 5,632
  • 3
  • 24
  • 24
0

One alternative would be to add a toolbar to the keyboard with something like a "done" button that will dismiss it. You can find some sample code about that here. One second approach would be to dismiss the keyboard when the user selects a different cell or even when the tableView scrolls. In order to do that, you can add relevant code in -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath or in -(void)scrollViewDidScroll:(UIScrollView *)scrollView respectively.

Community
  • 1
  • 1
phi
  • 10,634
  • 6
  • 53
  • 88
0

This can get a little tricky if your new at iOS. The way I handle a UITextView in a UITableViewCell is I make a custom UITableViewCell subclass with an outlet for the UITextView. Then set your cell in interface builder to be of that subclass. In the CellForRowAtIndexPath: set the delegate to self. Then in the DidSelectRowAtIndexPath you call the delegate for the TextView based on the indexPath, this way the keyBoard will dismiss for the correct row if you touch the background. If you want it to dismiss when the user touches any cell just call the delegate without specifying the indexPath. The Delegate is TextViewShouldEndEditing:.Ill post some code if you want.

Hubert Kunnemeyer
  • 2,261
  • 1
  • 15
  • 14