I found a weird white space on UITableView
for iPhone 6 Simulator (iOS 8) on Xcode 6 GM. I have tried to set the SeparatorInset
fr
In my case in Xcode 6.2, in addition to Will Q's answer, I have to go to Main.storyboard > select the UITableViewCell > Attributes Inspector. Change Separator dropdown list from Default Insets to Custom Insets. Change the left inset from 15 to 0.
To make your UITableView separator insets to zero for both iOS7 and iOS8, instead of making a change in the code, make a change in the xib for the UITableView by changing the View->Mode->Aspect Fill.
Thanks Student for pointing me to the right direction with the comment "Try this self.myTableView.layoutMargins = UIEdgeInsetsZero;" This line of code will only work on iOS 8 because layoutMargins is only available from iOS 8. If I run the same code on iOS 7, it will crash.
@property(nonatomic) UIEdgeInsets layoutMargins Description The default spacing to use when laying out content in the view. Availability iOS (8.0 and later) Declared In UIView.h Reference UIView Class Reference
Below is the right answer to solve this weird white space by setting the tableview layoutMargins
and cell layoutMargins
as UIEdgeInsetsZero
if it exists (for iOS 8). And it will not crash on iOS 7 as well.
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[tableView setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
See the screen shot below:-