Disabling automatic scrolling of UITableView when editing UITextField inside UITableViewCell

后端 未结 9 921
别跟我提以往
别跟我提以往 2020-11-30 00:40

I\'m using custom UITableViewCells inside my UITableView. Each of these UITableViewCells is pretty high and contains a UITextFie

9条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 00:48

    The issue for me was not so much that it scrolled but that it took the text view being edited off the screen.

    So instead of preventing the scrolling, I just rescroll the tableview to where I want when the editing is triggered, like this:

    public func textViewShouldBeginEditing(textView: UITextView) -> Bool {            
      dispatch_async(dispatch_get_main_queue()) {
        tableViewController.tableView.scrollToRowAtIndexPath(self.indexPath!, atScrollPosition: UITableViewScrollPosition.Middle, animated: true)
      }
      return true
    }
    

提交回复
热议问题