I have a subclassed UITableViewCell and in that class I have a drawRect method that draws a frame for each cell. Each cell have a different size (like in Twitter App) and for some reason this is causing my scrolling to be slow. Is there a way around this?
here is my code for the drawRect in the UITableViewCell subclass:
- (void)drawRect:(CGRect)rect {
// Drawing code
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(c, [[UIColor whiteColor] CGColor]);
CGContextSetStrokeColorWithColor(c, [[UIColor lightGrayColor] CGColor]);
CGContextSetLineWidth(c, 0.5);
CGFloat minx = CGRectGetMinX(rect) , midx = CGRectGetMidX(rect), maxx = CGRectGetMaxX(rect) ;
CGFloat miny = CGRectGetMinY(rect) , midy = CGRectGetMidY(rect) , maxy = CGRectGetMaxY(rect) ;
minx = minx + 10;
miny = miny + 10;
maxx = maxx - 10;
maxy = maxy - 10;
CGContextSaveGState(c);
CGContextMoveToPoint(c, minx, midy);
CGContextAddArcToPoint(c, minx, miny, midx, miny, 4.0f);
CGContextAddArcToPoint(c, maxx, miny, maxx, midy, 4.0f);
CGContextAddArcToPoint(c, maxx, maxy, midx, maxy, 4.0f);
CGContextAddArcToPoint(c, minx, maxy, minx, midy, 4.0f);
// Close the path
CGContextClosePath(c);
// Fill & stroke the path
CGContextSetShadowWithColor(c, CGSizeMake(.5, 1), 2.5, [UIColor lightGrayColor].CGColor);
CGContextDrawPath(c, kCGPathFillStroke);
CGContextRestoreGState(c);
CGContextSetFillColorWithColor(c, [[UIColor whiteColor] CGColor]);
CGContextSetStrokeColorWithColor(c, [[UIColor lightGrayColor] CGColor]);
CGContextSetLineWidth(c, 0.5);
CGContextMoveToPoint(c, minx, midy);
CGContextAddArcToPoint(c, minx, miny, midx, miny, 4.0f);
CGContextAddArcToPoint(c, maxx, miny, maxx, midy, 4.0f);
CGContextAddArcToPoint(c, maxx, maxy, midx, maxy, 4.0f);
CGContextAddArcToPoint(c, minx, maxy, minx, midy, 4.0f);
CGContextClosePath(c);
CGContextDrawPath(c, kCGPathFillStroke);
}
Here is the code for cell initialization and height:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
TimeLineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[TimeLineTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
int cellHeight = 500 + indexPath.row;
return cellHeight;
}