ios8 UITableView设置 setSeparatorInset:UIEdgeInsetsZero不起作用的解决办法(去掉15px空白间距)
但是在ios8中,设置setSeparatorInset:UIEdgeInsetsZero 已经不起作用了。下面是解决办法:
首先在viewDidLoad方法加入以下代码:
if(leftTable!.respondsToSelector("setLayoutMargins:")){
leftTable?.layoutMargins=UIEdgeInsetsZero
}
if(leftTable!.respondsToSelector("setSeparatorInset:")){
leftTable!.separatorInset=UIEdgeInsetsZero;
}
然后在UITableView的代理方法中加入以下代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let Identifier="MultilevelTableViewCell";
var cell=tableView.dequeueReusableCellWithIdentifier(Identifier);
if(cell == nil){
cell=UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier:Identifier)
}
if(cell!.respondsToSelector("setLayoutMargins:")){
cell!.layoutMargins=UIEdgeInsetsZero
}
if(cell!.respondsToSelector("setSeparatorInset:")){
cell!.separatorInset=UIEdgeInsetsZero;
}
return cell!
}
这样不出意外的话,Table的分割线就没有空白间距了。
作者:来碗杂酱面
出处:http://www.cnblogs.com/brance/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
如果文中有什么错误,欢迎指出。以免更多的人被误导。
遇到了任何问题可以联系我邮箱:292692700@qq.com(QQ也是这个 去掉后缀即可)