provideal / MMGridView

A simple grid view / dashboard component for iOS
324 stars 58 forks source link

Lag problem with UI refresh #19

Closed dearscoop closed 11 years ago

dearscoop commented 12 years ago

In my app I discovered that I was hitting a totally random lag with the UI update. The lag was anywhere from nothing (instant update) to over 20 seconds.

Eventually I came across this post which helped me resolve the issue. http://stackoverflow.com/questions/7629485/what-is-the-proper-way-to-make-it-so-core-graphics-does-not-lag

Basically MMGridview should not be setting up the grid cells in the drawRect: method.

I simply changed the name of this method to drawCells and called it directly rather than via setNeedsDisplay, and presto, no more lag.

Love this class by the way. Thanks for sharing it.

Cavalier-Ly commented 11 years ago

I've ran into a similar situation when attempting to reload my MMgridview instance with updated datadsource I set the images for the cells with the help of SDWebImage class ,for the every first time I run my app,my gridview shows perfectly,but when i reload it ,it turns out that every cell's image background is lost can anyone give me an advice to solve it? pretty thx

renspr commented 11 years ago

Hi,

@dearscoop sorry can't reproduce. I can't see why it is wrong draw the cells in drawRect:? drawRect: is called once on view initialization, orientation change and when calling reloadData manually. This seems fine to me.

@Cavalier-Ly Sorry no idea. I can't reproduce the drawing lag.

We use this component with max. 6-9 cells and static images without problems, so I assume you both have another use case. Can you reproduce the lag with the provided example that uses 42 cells?

Regards,

René

Cavalier-Ly commented 11 years ago

Problem got solved when I updated my MMgridview source to the latest version Showing the cell image within a ImageView seems much better both in image auto-scaling and refreshing Thanks for your efforts on this @renspr ! BTW, I wonder that does the backgrounview in defaultcell make any sense any more in the latest version,please point out that if there was.

renspr commented 11 years ago

You are right. The background view should be considered obsolete. This was a rather stupid implementation on my side.

Cavalier-Ly commented 11 years ago

Huh,actually I have the same so-called "stupid" implementation with yours on an android project which has the similar UI with the one I am dealing with,an ImageView in android could not add any subview ,so I had to set the image in the cellview's background and cover it with a textlabel... By now I have another problem--is it possible to add a particular UISwipeGesture(right direction) to MMgridview's first page so I can drag another viewcontroller in to cover the window and show something in it,I have mostly implemented this by covering the MMgridview with a totally transparent blank custom UIView(userinteractionEnabled set to YES when scrolled to page index 0) to block the swipe gesture,and this dosen't perform perfectly Would you please give me some suggestions to implement this well? thanks

renspr commented 11 years ago

Hi, with "stupid" I mean that it was actually never needed to use the image as a background image for that view. Using UIImage view in that case is the obvious implementation and I should have used it in the first place. That does not mean that using a background image is generally a bad idea though.

For your UISwipeGesture problem I have no clue. This has nothing todo with the grid. The grid is just a UIScrollView that pages in horizontal direction. Overlay the UIScrollView with a UISwipeGesture is nothing what I have tried so far, sorry.

Best, René

Cavalier-Ly commented 11 years ago

Thanks for your reply,I'll go on looking for the solution . Good luck to our projects!