I've got a UITextView inside a UIScrollView (specifically, the text view is in a UITableViewCell in a table). When I type in the text view and hit return to make some new lines (and the text in the text view becomes too long for it to contain vertically), it scrolls both the text view itself (which is okay) and the table/table cell that contains it (which I would like to prevent). Is there some way to prevent this behaviour?
- The UITableView has scrollEnabled set to NO, yet the UITextView still causes it to scroll.
- I've thought about subclassing UITextView and overriding scrollRectToVisible to do nothing, but I don't mind the text view itself scrolling, I want to stop it scrolling the containing view.
- Similarly, setting scrollEnabled to NO on the text view only prevents it from scrolling, not the table/table cell.
- The text view is not obscured by the keyboard, but it seems like it still wants to move closer to the top of the screen.
I think Jonathan M has the right solution (I upvoted him).
I had UITextView in a UITableViewCell that would occasionally scroll the table view up when the user was typing text and the text went beyond the content rect of the scroll view.
Instead of subclass, I used a category.
This question is almost a year old, but it drove me crazy for a while.
I finally managed to disable that behavior by subclassing
UITextView
, overriding a method namedscrollRectToVisibleInContainingScrollView
and do absolutely nothing in the implementation.It is a private, undocumented method of UITextView that apparently handles the auto-scrolling of a super view. Since all we're doing is subclassing and redefining a method (and thus not relying on it existing beforehand), it should be acceptable.
It is not clear how exactly you want it to work. In case you just need to prevent autoscrolling then this answer might help. How about to get similar behavior as in standard reminder app, when the height of
UITextView
increases? I have implemented such behaviour in samples for my TableKit libraryFor what it's worth, I've finally resolved this issue by removing the UITextView from the UITableViewCell (and adding it to the view controller that contains the table view) while editing, then returning it to the UITableViewCell when finished.