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 8278947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:10:24+00:00 2026-06-08T09:10:24+00:00

I have an iPad app which uses an open source class MMGridView. Basically I

  • 0

I have an iPad app which uses an open source class MMGridView.
Basically I perform a CoreData query, and then this class draws boxes on the screen in a grid pattern to represent the results. The boxes include photos.
Everything works fine, except that sometimes there is an unexplained time lag until the UI is drawn on the screen. Sometimes the refresh is instant, sometimes it is over 20 seconds. It appears very random in its behaviour.

I’ve managed to determine that:

  • DrawRect is being called every time.
  • that the lag is not occurring in the DrawRect method.
  • when I run the time profiler, from what I can tell, nothing is happening during this time lag

My question is, what happens after DrawRect is called that I can try to look at to identify the problem?

Absolutely any ideas would be greatly appreciated.

Note also that user interaction is able to cut the lag short.
– rotating the iPad (triggers redraw) always makes the ui refresh immediately
– pressing the button to redo the same query will generally refresh the screen

So it really appears like there is just some random delay I’m hitting, as opposed to any sort of processor/work load issue. Problem is that programmatically, I can’t tell if the UI has updated or not. Otherwise I could just ask it to redraw again.

I’m including the code from the DrawRect method just in case that sparks any ideas, but from what I can tell, this method completes before the lag occurs.

- (void)drawRect:(CGRect)rect {

if (self.dataSource && self.numberOfRows > 0 && self.numberOfColumns > 0) {
    NSInteger noOfCols = self.numberOfColumns;
    NSInteger noOfRows = self.numberOfRows;
    NSUInteger cellsPerPage = noOfCols * noOfRows;
    NSLog(@"rows = %d, cols = %d", noOfCols, noOfRows);
    CGRect gridBounds = self.scrollView.bounds;
    CGRect cellBounds = CGRectMake(0, 0, gridBounds.size.width / (float)noOfCols, 
                                   gridBounds.size.height / (float)noOfRows);

    CGSize contentSize = CGSizeMake(self.numberOfPages * gridBounds.size.width, gridBounds.size.height);
    [self.scrollView setContentSize:contentSize];

    for (UIView *v in self.scrollView.subviews) {
        [v removeFromSuperview];
    }

    for (NSInteger i = 0; i < [self.dataSource numberOfCellsInGridView:self]; i++) {
        MMGridViewCell *cell = [self.dataSource gridView:self cellAtIndex:i];
        [cell performSelector:@selector(setGridView:) withObject:self];
        [cell performSelector:@selector(setIndex:) withObject:[NSNumber numberWithInt:i]];

        NSInteger page = (int)floor((float)i / (float)cellsPerPage);
        NSInteger row  = (int)floor((float)i / (float)noOfCols) - (page * noOfRows);

        CGPoint origin = CGPointMake((page * gridBounds.size.width) + ((i % noOfCols) * cellBounds.size.width), 
                                     (row * cellBounds.size.height));

        CGRect f = CGRectMake(origin.x, origin.y, cellBounds.size.width, cellBounds.size.height);
        cell.frame = CGRectInset(f, self.cellMargin, self.cellMargin);

        [self.scrollView addSubview:cell];
    }
}
}
  • 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-08T09:10:25+00:00Added an answer on June 8, 2026 at 9:10 am

    Ok problem solved due to a very clear and concise description of when to use and when not to use drawRect: by Peter Hosey in a response to this question.
    What is the proper way to make it so core graphics does not lag?

    Basically, this is a bug in the Open source class MMGridView which I am using, because it should not be using drawRect: to setup the boxes or cells on the UIScrollView. This is because there is no actual drawing taking place.

    So by changing the name of the method above and calling it directly where I previously called setNeedsDisplay, there is no longer any random lag.

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

Sidebar

Related Questions

I have an iPhone/iPad app which uses Core Data. In my DB I have
I have an app that uses NASA live TV stream for the iphone/ipad which
I have this iOS 3.2 app (iPad) which has lots of content, and a
I have an iPad app which has a funky Path-style menu which is present
I have a iPad app which is NOT modified for the new iPad with
I have an iPhone/iPad app which play a HTTP Live Stream of a tv
I have a basic iPhone/iPad app which has a ; a. List view &
I have an app which has different app identifier for iphone and ipad and
I have an iPad app that uses custom fonts though the UIAppFonts elements in
I have this iPad app using Storyboard. There are some file that are marked

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.