Disabling automatic scrolling of UITableView when editing UITextField inside UITableViewCell

后端 未结 9 871
别跟我提以往
别跟我提以往 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条回答
  • You can try doing the following:

    self.tableView.scrollEnabled = NO;
    

    This should disable the scrollview in the tableview.

    0 讨论(0)
  • 2020-11-30 01:10

    Define properties for your UITableViewController:

    @property (nonatomic) BOOL scrollDisabled;
    @property (nonatomic) CGFloat lastContentOffsetY;
    

    Before you call becomeFirstResponder:

    // Save the table view's y content offset 
    lastContentOffsetY = tableViewController.tableView.contentOffset.y;
    // Enable scrollDisabled
    scrollDisabled = YES;
    

    Add the following code to your table view controller:

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        if (self.scrollDisabled) {
            [self.tableView setContentOffset:CGPointMake(0, lastContentOffsetY)];
        }
        ...
    }
    

    After you call resignFirstResponder, set scrollDisabled = NO.

    0 讨论(0)
  • 2020-11-30 01:11

    You could disable the automatic content inset adjustment like so:

    tableView.contentInsetAdjustmentBehavior = .never
    
    0 讨论(0)
提交回复
热议问题