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

后端 未结 9 2419
孤街浪徒
孤街浪徒 2020-12-07 07:36

I have a few (grouped style) tables in my iphone app (only on part of the screen and added with Interface Builder though, not subclassed from UITableViewC

9条回答
  •  半阙折子戏
    2020-12-07 07:56

    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.
    

提交回复
热议问题