views:

349

answers:

1

Hello,

I'm try to create a fast scrolling list using the creator of Tweetie, Loren Brichter's technique. I believe the idea is to "do your own drawing" instead of using using subviews and images in the UITableViewCell.

Below I have extend his example to include an image and I'm not sure if this is the correct way to do it?

I have been trying to play around with CALayer and am struggling to 'get it'. So here in this example I just drawn out an image. But I'm unsure – this seems the same as how an image is displayed in a view? Next I will use UIGraphicsBeginImageContext to include more images (e.g. footerImage)

Is what I am doing in this example going to improve performance over creating it all in IB?

Thanks

- (void)drawContentView:(CGRect)r
{
    CGContextRef context = UIGraphicsGetCurrentContext();

    UIColor *backgroundColor = [UIColor whiteColor];
    UIColor *textColor = [UIColor blackColor];

    if(self.selected)
    {
     backgroundColor = [UIColor clearColor];
     textColor = [UIColor whiteColor];
    }

    [backgroundColor set];
    CGContextFillRect(context, r);

    // This is where I add the image to the example
    //
    CGRect profile = CGRectMake(0, 0, 320, 20);
    [headerImage drawInRect:profile];

    CGPoint p;
    p.x = 12;
    p.y = 9;

    [textColor set];
    CGSize s = [firstText drawAtPoint:p withFont:firstTextFont];

    p.x += s.width + 6; // space between words
    [lastText drawAtPoint:p withFont:lastTextFont];
}
+1  A: 

Yes, this technique will improve performance over a straight IB cell. But if you make all elements of a cell opaque, IB performance can be pretty decent - you may want to try that first before you go down the path of a lot of code to create what are otherwise simple cells.

Kendall Helmstetter Gelner