Ciaran Lawlor
Ciaran Lawlor

Reputation: 63

drawRect causes slow scrolling even though it is not being called

In my app I have a scrollView with about 20 subviews in it. Each of these subviews has a drawRect method that at the moment looks like this:

- (void)drawRect:(CGRect)rect
{
    NSLog(@"drawRect called");
}

When the subviews are added, drawRect is called, however when I scroll it is very slow even though drawRect is not called again.

If I remove the implementation for drawRect, then scrolling is completely normal. Even if I can't get rid of the slow scrolling, is there an alternative to drawRect which I could use instead?

Upvotes: 4

Views: 669

Answers (2)

hotpaw2
hotpaw2

Reputation: 70743

You could try assigning pre-drawn CGImages to the contents of each custom view's CALayer, before the view first appears. This may be faster than using a drawRect to customize a view's appearance.

Upvotes: 0

pasawaya
pasawaya

Reputation: 11595

Why are you calling drawRect if it is only logging that it was called? If that is it's only purpose for you, then just don't call it. In fact, I believe when you first create a class that inherits from UIView that has the drawRect method in it, it is commented out and above the commented out drawRect method, it says something along the lines of "Do not call this method if it does not do any drawing on screen as it takes up a significant amount of memory". Basically, don't call it in your case.

Hope this helps.

Upvotes: 1

Related Questions