How to disable scrolling in UITableView table when the content fits on the screen How to disable scrolling in UITableView table when the content fits on the screen ios ios

How to disable scrolling in UITableView table when the content fits on the screen


I think you want to set

tableView.alwaysBounceVertical = NO;


In Swift:

tableView.alwaysBounceVertical = false


You can verify the number of visible cells using this function:

- (NSArray *)visibleCells

This method will return an array with the cells that are visible, so you can count the number of objects in this array and compare with the number of objects in your table.. if it's equal.. you can disable the scrolling using:

tableView.scrollEnabled = NO;

As @Ginny mentioned.. we would can have problems with partially visible cells, so this solution works better in this case:

tableView.scrollEnabled = (tableView.contentSize.height <= CGRectGetHeight(tableView.frame));

In case you are using autoLayout this solution do the job:

tableView.alwaysBounceVertical = NO.