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
from both storyboard and also the code, but the white space is till there.
The following code works on iOS 7 but not on iOS 8 (iPhone 6 simulator).
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
}
I attached screenshot below:
I am using AutoLayout by the way. I hope someone can show me a way to remove the weird white space on the TableView
.
Just add the following:
Try to create a UITableViewCell class category and add this getter
in iOS7 this will not be called cos there's no this property in SDK,and will not cause any crash; in iOS8 this will be called every time you use the cell
It works for me
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.
Below is the right answer to solve this weird white space by setting the
tableview layoutMargins
andcell layoutMargins
asUIEdgeInsetsZero
if it exists (for iOS 8). And it will not crash on iOS 7 as well.See the screen shot below:-
See iOS 8 UITableView separator inset 0 not working
Basically, you need to set both the cell.layoutMargin as well as the tableView's layoutMargin. YMMV, but I had to set the table view up in layoutSubviews before it would work!
IOS8 introduce a new concept named Configuring Content Margins , a new property named layoutMargins is also introduced , for the details of the property , please refer to the Apple Doc . The type of layoutMargins is UIEdgeInsets , by default the value is {8,8,8,8} . To remove the seperator line of TableView in IOS8 , in addition to set
tableView.seperatorInset = UIEdgeInsetsZero
, you must also do as :First define the macro
In the UITableViewDelegate method add :
Doing these will remove the seperator line . You can also do as follow :
and in the UITableViewDelegate method add :
I've tried many ways, none of them work but this one works for me.