objective c UITableView无法使用自定义单元格和意见 [英] objective c UITableView not scrolling smooth with custom cell & views

查看:81
本文介绍了objective c UITableView无法使用自定义单元格和意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望tableview在每个可滚动的行中显示多个图像。为此我在自定义tableView单元格中使用 UITableView 自定义UITableViewCell ,我生成具有多个视图的滚动视图&安培;图像,所以当我滚动表时,它不能顺畅地滚动它的闪烁。任何人都可以建议我以更好的方式做到这一点吗?

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];
}


推荐答案

如果要滚动tableview顺利,你应该注意几个提示。

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 examples / documentation
建议的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.

当然,大部分时间,如果你的tableview滚动不顺畅,主要问题是你在同步中加载图像。

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.

这篇关于objective c UITableView无法使用自定义单元格和意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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