iOS UITableView适配 那些坑

1. 消除多余的行

tableView.tableFooterView = [[UIView alloc]init];

2. 分割线缩进为0即分割线两边顶到头

如果你有兴趣了解下面iOS8新特性可以看看由Chun发表于Chun Tips的文章 这里,或者狂灬的草人的文章这里

cell.separatorInset = UIEdgeInsetsZero;   // iOS7 
cell.preservesSuperviewLayoutMargins = NO;  // iOS8 +
cell.layoutMargins = UIEdgeInsetsZero;  // iOS8 +

3. 取消Cell的选中

一般用在didSelectRowAtIndexPath方法里,此方法不会引起调用
tableView:willSelectRowAtIndexPath:
tableView:didSelectRowAtIndexPath:

 [tableView deselectRowAtIndexPath:indexPath animated:YES];

4. 利用SDWebImage自适应图片高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {  
    // 先从缓存中查找图片  
    UIImage *image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey: self.imgArray[indexPath.row]];  
      
    // 没有找到已下载的图片就使用默认的占位图,当然高度也是默认的高度了,除了高度不固定的文字部分。  
    if (!image) {  
        image = [UIImage imageNamed:kDownloadImageHolder];  
    }  
  
    //手动计算cell  
    CGFloat imgHeight = image.size.height * [UIScreen mainScreen].bounds.size.width / image.size.width;  
    return imgHeight;  
}  
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容