Reputation: 3222
I am creating a custom Table by designing my own UITableViewCell
in Xcode and loading it in cellForRowAtIndexPath
. I am facing scrolling problems; the table scrolls really slow and not smooth at all. In each cell I have:
UIImageView
where the 3rd one is added dynamically when neededUILabel
UITextView
UIButton
, some 1 UIButton
, and the majority no buttons at allUIView
The sizes of the image views, text view, and buttons are different in every cell. To prevent calculating the sizes every time the table is scrolled I load all the sizes in viewWillAppear
and store them in an array, and inside cellForRowAtIndexPath
I only load the sizes from the array and set them to the desired objects.
I tried all the ideas that I found on the web (like loading the images in the body of if(cell == nil)
as shown here, or not de-queue the cells...) but nothing solved my problem.
On the other hand I notice that the chatting app WhatsApp uses similar amount of items per cell (example when the user receives an image, there are 2 buttons View and Forward, the image thumbnail, a check mark image next to the thumbnail, a date label, a bubble image behind the thumbnail...) but the scrolling there is very smooth.
My scrolling is slow even if I have 10 cells in the table only. Here are my questions:
Many thanks in advance.
Upvotes: 2
Views: 2605
Reputation: 5282
try this:
-webkit-overflow-scrolling: touch;
taken from here:
http://css-tricks.com/snippets/css/momentum-scrolling-on-ios-overflow-elements/
Upvotes: 0
Reputation: 7065
Slow operation of a TableView when using images is NORMALLY because of resizing operations. The last app I made had images coming from the web. as an example, one image that was coming in was a 4k pixel x 4k pixel image. All others were much larger than the thumbnail sized image I was trying to display. Long and short of it is, every time an image goes off screen, the image is moved out of RAM and back into flash, this is to help preserve RAM memory. The problem is that what stays in flash is the original UIImage that you are assigning to your UIImageView. A UIImage retains the original sized image. Thus now every time the image comes back on screen it has to be RESIZED from its original size (smaller or bigger than you wish to display). Every time that 4k px x 4k px image came back on screen, the TableView would glitch. The trick is to size the images to exactly what you wish to display prior to assigning it to the UIImage backing the UIImageView. As an exemplary note, this table view only was displaying ~ 10 to 12 items at a time and it was still extremely slow (even after all images war completely loaded from the web).
Another potential slowness. I had another app I built where I originally wished for the data being displayed to be selectable for copy and past. You can do this with UITextView objects. Problem is that the table of values I was outputting was 17 columns wide by 218 rows. In this case because each UITextView has scroll capability (even when I TURNED IT OFF) was causing each UITextView to have to re-calculated it's own sub-view display coordinates, etc... causing very SLOW overall table scrolling. In the end, if the data doesn't need to be edited, or copy and pasted, you really should only be displaying it with UILabel objects. When I did this, the performance of my UITableView went up immensely.
Upvotes: 1
Reputation: 8546
I had the same problem with multiple image per cell. UITextView is killing it if each cell has one. Also hide images you don't want to show and try to not loop into an array to find if yes or no you should show or hide an image but make an array of BOOL that can be read
Upvotes: 1