一、.重用cell
在数据源方法中,在可见的页面重复绘制
OC方法中 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; SWIFT方法 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
因此 ,可以在该方法中做一些处理操作
OC处理操作 static NSString * ReusedCellID = "ReusedCellID"; UITableViewCell * cell = tableView.dequeueReusableCellWithIdentifier( ReusedCellID, forIndexPath: indexPath) swift的处理操作 private let ReusedCellID = "ReusedCellID" let cell = tableView.dequeueReusableCellWithIdentifier( ReusedCellID, forIndexPath: indexPath)
这样,就可以防止cell无限的被创建,重用cell
二、cell的图片异步加载
当设置图片异步加载之后,cell 的图片就放在了子线程中执行,但是,如果此时下滑,也会出现卡顿的现象
解决办法:
异步下载,在以下两个方法中下载图片、
// 当结束拖拽的时候 - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate // 减速的时候 - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
具体操作:
//获取可见部分的对象 NSArray *visiblePaths = [self.tableView indexPathsForVisibleRows]; for (NSIndexPath *indexPath in visiblePaths) { //获取的dataSource里面的对象,并且判断加载完成的不需要再次异步加载 <code> } 同时在cell绘制中也做限制 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (self.tableView.dragging == NO && self.tableView.decelerating == NO) { //开始异步加载图片 <code> }}
三、尽量少用透明的图层
内部的渲染机制
时间: 2024-08-05 02:12:54