UITextView in a UITableViewCell smooth auto-resize shows and hides keyboard on iPad, but works on iPhone

后端 未结 2 597
别那么骄傲
别那么骄傲 2020-12-07 11:02

I have implemented a custom UITableViewCell which includes a UITextView that auto-resizes as the user types, similar to the \"Notes\" field in the Contacts app. It is workin

2条回答
  •  独厮守ぢ
    2020-12-07 11:28

    you should return NO in:

     -(BOOL) textViewShouldEndEditing:(UITextView *)textView
    

    if you would like to show keyboard at all times. You should handle cases, which keyboard should be hidden, by returning YES to this delegate function.

    edit:

    I dug a little more, when [tableView endUpdates] called, it basically does 3 things :

    1. Disables user interaction on the tableView
    2. Updates cell changes
    3. Enables user interaction on the tableView

    The difference between SDKs(platforms) is at [UIView setUserInteractionEnabled] method. As UITableView does not overrite setUserInteractionEnabled method, it is called from super (UIView).

    iPhone when setUserInteractionEnabled called, looks for a private field _shouldResignFirstResponderWithInteractionDisabled which returns NO as default, so does not resign the first responder (UITextView)

    But on iPad there is no such check AFAIK, so it resignes UITextView on step 1, and sets focus and makes it first responder on step 3

    Basically, textViewShouldEndEditing, which allows you to keep focus, according to SDK docs, is your only option ATM.

    This method is called when the text view is asked to resign the first responder status. This might occur when the user tries to change the editing focus to another control. Before the focus actually changes, however, the text view calls this method to give your delegate a chance to decide whether it should.

提交回复
热议问题