IOS8 设置TableView Separatorinset 分割线从边框顶端开始
http://www.cocoachina.com/bbs/read.php?tid-233228.html
在ios8上 [
TableView
setSeparatorInset
:
UIEdgeInsetsMake
(
0
,
0
,
0
,
0
)];不起作用
经过测试加入下面方法 在ios7 8上都可以正常工作
-(void)viewDidLayoutSubviews
{
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
http://stackoverflow.com/questions/25762723/remove-separatorinset-on-ios-8-uitableview-for-xcode-6-iphone-simulator
This line of code will only work on iOS 8 becauselayoutMargins is only available from iOS 8. If I run the same code on iOS 7, it will crash.
这行代码将只能在iOS 8的工作,因为layoutmargins只是从iOS 8可用。如果我在iOS 7上运行相同的代码,它会崩溃。
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];
}
}