问题出现的原因:创建tableView时使用的style是UITableViewStylePlain
解决办法:
在创建tableView时,self.automaticallyAdjustsScrollViewInsets = NO;
官方文档是这么写的:
@property(nonatomic, assign) BOOL automaticallyAdjustsScrollViewInsets
Discussion
Default value is
YES
, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set to
NO
if you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy.