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

来源:互联网 发布:万网域名可以不备案吗 编辑:程序博客网 时间:2024/06/07 06:15

       面对在开发中遇到的需要将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 ([cellrespondsToSelector:@selector(setLayoutMargins:)]) {

        [cellsetLayoutMargins:UIEdgeInsetsZero];

    }


 

0 0