您的位置:首页 > 移动开发 > IOS开发

iOS 开发中问题 ——tableView分行线距离左侧15像素空白的解决办法

2015-07-09 10:43 483 查看

       面对在开发中遇到的需要将tableView分行线左侧空白出来的15像素去掉的问题,可以采用在tableView的代理方法里面-(UITableViewCell
*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath;中对返回的cell进行[cell setSeparatorInset:UIEdgeInsetsZero]处理;这个方法是针对ios7进行的处理,在ios8中却并不起作用。在iOS
8中需要在-(void)viewDidLoad;中添加

  if ([self.listTableViewrespondsToSelector:@selector(setSeparatorInset:)])
{

        [self.listTableViewsetSeparatorInset:UIEdgeInsetsZero];
    }
   if ([self.listTableViewrespondsToSelector:@selector(setLayoutMargins:)])
{

        [self.listTableViewsetLayoutMargins:UIEdgeInsetsZero];
    }
这两个方法,并且还需要多完成一个tableView的代理方法
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell
*)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
并在该方法中进行如下操作
 if ([cellrespondsToSelector:@selector(setSeparatorInset:)])
{
        [cellsetSeparatorInset:UIEdgeInsetsZero];
    }
   if ([cell
respondsToSelector:@selector(setLayoutMargins:)]) {
        [cellsetLayoutMargins:UIEdgeInsetsZero];
    }


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS