UITableView scrolling slow, memory leak issue

后端 未结 2 427
日久生厌
日久生厌 2021-01-23 08:36

I have a UITableView and a UITableCell subclass. Each table cell has two scrollviews that each rotate a dynamic amount of labels, which ar

相关标签:
2条回答
  • 2021-01-23 08:49

    The first thing you could do is try to reuse UILabels in createPopularLinkLabels. Right now, you are just removing them before adding more.

    But if the number of popular links is not the same in all the cells, then you will have to remove the remaining ones or hide them and there will be no way to avoid memory allocations.

    A better solution would be to insert a custom UIView inside your scroll view and draw all the texts manually instead of creating tons of subviews.

    Hope this helps, Thomas

    0 讨论(0)
  • 2021-01-23 09:07

    Are you using ARC? If not, you should autorelease to

    cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]
    

    Cell objects are reused and you do not need to re-add subviews each time you change the contents. Just change the data and update the label frames if needed.

    If you have distinctly different cells, consider using separate custom cell classes. You will need to use a separate value for the reuseIdentifier.

    Also consider not creating a custom cell but just adding elements to the standard UITableViewCell. Read this about styling a cell.

    0 讨论(0)
提交回复
热议问题