UITableView在iOS9后新增了一個屬性cellLayoutMarginsFollowReadableWidth,該屬性會影響UITableViewCell在iPad下的顯示愿阐,且該屬性默認為YES彬坏。
當你發(fā)現(xiàn)在iPad下UITableViewCell不能占滿整個UITableView的寬度時族跛,只需將該屬性設(shè)置為NO即可辜羊。
在viewDidLoad方法里添加以下代碼即可:
[self.tableView setCellLayoutMarginsFollowReadableWidth:NO];
========可恥的分割線===========
另外有一種情況參考:
https://stackoverflow.com/questions/38836036/uitableview-does-not-fill-out-entire-screen-on-ipad
添加以下代碼可以解決
-(void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath{
if([tableViewrespondsToSelector:@selector(setSeparatorInset:)]) {
[tableViewsetSeparatorInset:UIEdgeInsetsZero];
}
if([tableViewrespondsToSelector:@selector(setLayoutMargins:)]) {
[tableViewsetLayoutMargins:UIEdgeInsetsZero];
}
if([cellrespondsToSelector:@selector(setLayoutMargins:)]) {
[cellsetLayoutMargins:UIEdgeInsetsZero];
}
}