如果在滚动时分配了UITableViewCell,则不应该重新分配UITableViewCell。但是。我怎样才能防止这种情况发生?UITableViewCell在滚动时一次又一次分配
回答
如果你想重用细胞,然后在的cellForRowAtIndexPath代码一样,
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
CGRect CellFrame;
CGRect nameLabelFrame;
CGRect countLabelFrame;
CellFrame = CGRectMake(0, 0, 320, 80);
nameLabelFrame = CGRectMake(10, 10, 270, 50);
countLabelFrame = CGRectMake(10, 58, 270, 12);
cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:CellIdentifier] autorelease];
UILabel *lblTemp;
//UIImageView *imgTemp;
lblTemp = [[UILabel alloc] initWithFrame:nameLabelFrame];
lblTemp.tag = 1;
[cell.contentView addSubview:lblTemp];
[lblTemp release];
lblTemp = [[UILabel alloc] initWithFrame:countLabelFrame];
lblTemp.tag = 3;
[cell.contentView addSubview:lblTemp];
[lblTemp release];
}
//And outside of if condition access these labels by this
//UIConstruction
UILabel *nameLabel = (UILabel *)[cell viewWithTag:1];
UILabel *countLabel = (UILabel *)[cell viewWithTag:3];
一些事情,并使用这些标签或控制你想要超出这个东西如果条件
我不知道为什么这是downvoted ??? !!!! – KingofBliss
'initWithFrame:reuseIdentifier'在3.0中已被弃用,现在使用委托方法设置高度。另外,代替使用标签,对UITableViewCell进行子类化并将UILabels设置为该类的属性会更好,特别是因为当通过覆盖'setFrame来调整单元格大小时可以调整它们的大小:' – EmilioPelaez
@EmilioPelaez通过设置框架这并不意味着,你不会使用heightForRowAtIndexPath。这是为了调整frame.also我没有提供确切的解决方案。只是一个想法,没有人会写整个code.also还有另一种方法重用cell.so解决方案是重用该单元格。 – Ishu
- 1. 元素一次又一次
- 2. System.Runtime.InteropServices.COMException一次又一次
- 3. 守则一次又一次
- 4. UICollectionView图像一次又一次地在滚动中滞后加载
- 5. 一次又一次地调用功能
- 6. MongoDB一次又一次地往下走
- 7. Wordpress恶意软件一次又一次
- 8. 不用想一次又一次
- 9. 一次又一次给MYSQL错误
- 10. 网页一次又一次的折腾
- 11. 方法一次又一次调用
- 12. 一次又一次地重复输出
- 13. 一次又一次更新UIVIew
- 14. OpenCV VideoWriter ffmpeg一次又一次
- 15. 一次又一次的解析错误
- 16. 在滚动时一次又一次地在Ajax自动加载中加载相同的内容
- 17. UITableViewCell cellForRowAtIndexPath第一次滚动时调用大量的行
- 18. 如何一次又一次地连续重复文本动画
- 19. 如何一次又一次启动和停止后台线程?
- 20. IEnumerable和WCF - 又一次
- 21. 又一次findFragmentByTag()返回null
- 22. 更新基础上选择同一个表 - 又一次,又一次
- 23. 停止重新加载UItableView一次又一次在Iphone
- 24. Webview在列表视图中一次又一次地加载
- 25. 在Android中一次又一次旋转图像90度
- 26. mutiwrapper在多项目下载gradle一次又一次的行为
- 27. 项目是一次又一次地保存在sqlite数据库
- 28. 在Javascript中,一次又一次显示相同的结果
- 29. 在MySQL中一次又一次显示表数据?
- 30. 在应用程序购买被拒绝一次又一次
你必须写一些代码什么正在这样做,我们可以得到主意...... – iBapu