Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8085669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:12:04+00:00 2026-06-05T18:12:04+00:00

I am using -drawRect for the first time in an attempt to alternatively speed

  • 0

I am using -drawRect for the first time in an attempt to alternatively speed up a UITableView. However, the drawRect method seems to be slowing the table down quite largely.

Please can you tell me how I can improve the drawRect method below in order to speed up the table?

Edit—

In the drawRect method, I am writing two NSStrings to the cell’s view, two UIImages and a drop shadow to both of the NSStrings and one of the UIImages.

One of the aforementioned images is downloaded asynchronously and then setNeedsDisplay is called to draw that UIImage to the screen. I believe that this could initially be the reason for the lag occurring.

- (void) drawRect:(CGRect) rect {

    CGContextRef context = UIGraphicsGetCurrentContext();

    [[UIColor clearColor] set];

    CGContextFillRect(context, rect);

    CGContextSaveGState(context);
    CGContextSetShadow(context, CGSizeMake(1,1),1);
    //draw text here

    if (shouldDrawImage == YES) {

        CGContextDrawImage(context, CGRectMake(10, 10, 40, 40), self.image.CGImage);

    }

    CGContextDrawImage(context, CGRectMake(self.frame.size.width - 16, 0, 16, self.frame.size.height), [UIImage imageNamed:@"right_bar_including_holes"].CGImage);

    NSString *authorName = [[self.info objectForKey:@"user"] objectForKey:@"full_name"];

    [RGB(219, 240, 73) set];

    CGSize maximumLabelSize = CGSizeMake(self.frame.size.width - 10 - 55 - 16,9999);
    CGSize authorsize = [authorName sizeWithFont:[UIFont boldSystemFontOfSize:15]
                                     constrainedToSize:maximumLabelSize 
                                         lineBreakMode:UILineBreakModeWordWrap]; 
    [authorName drawInRect:CGRectMake(60, 10, self.frame.size.width - 60, authorsize.height) withFont:[UIFont boldSystemFontOfSize:15]];

    [RGB(249,249,249) set];

    NSString *description = [self.info objectForKey:@"description"];
    CGSize descriptionSize = [description sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeWordWrap];

    [description drawInRect:CGRectMake(60, authorsize.height + 15, descriptionSize.width, descriptionSize.height) withFont:[UIFont systemFontOfSize:14]];

    CGContextRestoreGState(context);

}

- (NSString *) reuseIdentifier {
    return NSStringFromClass([SlideCell class]);
}

- (void) updateCellInfo:(NSDictionary *)_info {
    [self setInfo:_info];

    UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
    [iv setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[[self.info objectForKey:@"user"] objectForKey:@"avatar"]]] placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *_image) {
        dispatch_async(dispatch_get_main_queue(), ^{
            shouldDrawImage = YES;
            self.image = [self roundedImage:_image];
            [iv release];
            [self setNeedsDisplay];
        });

    } failure:nil];

    [self setNeedsDisplay];

    [self setSelectionStyle:UITableViewCellSelectionStyleNone];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:12:06+00:00Added an answer on June 5, 2026 at 6:12 pm

    Yes – you run Instruments’ Time Profile on your app to tell you exactly how much time is spent, and where. It will tell you if it is the image, string, shadow, or something else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using drawRect for a custom UIButton subclass, it never seems to get called
I am using apple's custom table view cell code and modifying the drawRect code
I have a grouped UITableView with some large images. However, scrolling performance is quite
A couple of firsts here - first Android app and first time using MonoDroid
I have a custom UIView which is drawn using its -[drawRect:] method. The problem
In Quartz2D, can I draw any shapes without using drawRect:(CGRect)rect method?
I am drawing a circle in the -drawRect: method of my UIView using the
I'm using drawRect: in my UITableViewCell subclass for the rendering performance when scrolling; everything
Using PHP, I can convert MySQL data or static table data to csv, Excel,
i'm using drawRect inside a custom UIButton to draw a bordered button with an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.