目标C UITableView无法使用自定义单元& amp;平滑滚动意见 [英] objective c UITableView not scrolling smooth with custom cell & views

查看:60
本文介绍了目标C UITableView无法使用自定义单元& amp;平滑滚动意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望tableview在每一行中显示可滚动的多个图像.为此,我使用了 UITableView Custom UITableViewCell ,在自定义tableView单元格中,我正在生成具有多个视图&的滚动视图.图像,所以当我滚动表格时,滚动不流畅.谁能建议我以更好的方式做到这一点?

I want the tableview to display multiple images in each and every row which is scrollable. For this I'm using UITableView and Custom UITableViewCell, in custom tableView cell i'm generating scroll view with multiple views & images, So when i'm scrolling table its not scrolling smoothly its blinking. Can anyone suggest me to do this in better way?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
   // Products table view. 
   ProductCustomCell *cell = (ProductCustomCell *)[tableView dequeueReusableCellWithIdentifier:@"CatelogCell"] ;//] forIndexPath:indexPath]; 
   if (cell == nil) { 
      cell = [[ProductCustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CatelogCell"]; 
   } 
   cell.productCellDelegate = self; 
   [cell initProperties]; 
   [cell showProductsInScroll:catelogBundle];
}

推荐答案

如果要平滑滚动表视图,则应注意一些技巧.

if you want to scroll tableview smooth, several tips you should pay attention.

  1. 缓存行的高度(表视图可以经常请求此高度),-实际上,这不是阻止tableview滚动的关键点.

  1. Cache the height of the rows (the table view can request this frequently), -- actually this point isn't the key point to block your tableview scroll.

为表中使用的图像创建最近最少使用的缓存(并在收到内存警告时使所有不活动的条目无效)-您可以使用SDWebImage下载图像并缓存它们.有时,您可能希望缓存一些经常使用tableview的图像,并且如果当前视图为顶视图,即使收到内存警告,这些图像也可能无法释放.

Create a least-recently-used cache for the images used in the table (and invalidate all the inactive entries when you receive a memory warning) -- you can use SDWebImage to download image and cache them. And sometimes, you maybe want to cache some images that your tableview frequently used and these images could also don't free even you receive a memory warning if your current view is the top view。

UITableViewCell drawRect:中绘制所有内容,如果可能,请不惜一切代价避免使用子视图(或者,如果您需要标准的可访问性功能,则内容视图的 drawRect:)-这样可以节省一些成本,但是也可能会花费更多的时间来编写代码,并且可能难以维护代码.但是,在uitableviewcell上使用较少的视图确实很好,这将改善您的性能.

Draw everything in the UITableViewCell's drawRect: if possible avoid subviews at all costs (or if you require the standard accessibility functionality, the content view's drawRect:) -- it could save some cost, but it also may cost your more time to code and maybe hard to maintain codes. But it is really good to use less views on uitableviewcell, that will improve your performance.

使您的 UITableViewCell 的图层不透明(如果有的话,内容视图也一样)-请尽量减少不透明层.

Make your UITableViewCell's layer opaque (same goes for the content view if you have one) -- please use layer opaque as less as possible.

使用 UITableView 示例/文档推荐的reusableCellIdentifier功能-您必须遵循以下提示.

Use the reusableCellIdentifier functionality as recommended by the UITableView examples/documentation -- you must follow this tips.

避免未预先烘焙到 UIImage s中的渐变/复杂的图形效果-如第4点.

Avoid gradients/complicated graphical effects that aren't pre-baked into UIImages -- like point 4.

当然,大多数情况下,如果您的表格视图滚动不平滑,则主要问题是您要同步加载图像.

of course, most time, if your tableview scroll not smooth, the main problem is that you load image in synchronize.

使用仪器测试性能真的很好.

it's really good to use instruments to test the performance.

这篇关于目标C UITableView无法使用自定义单元& amp;平滑滚动意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆