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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:25:20+00:00 2026-06-04T15:25:20+00:00

I have implemented the following NSOperation, to draw N custom views – (void)main {

  • 0

I have implemented the following NSOperation, to draw N custom views

- (void)main {

    for (int i=0; i<N; i++) {

       << Alloc and configure customView #i >>
       //(customView is a UIView with some drawing code in drawrect)

       [delegate.view addSubview:customView];

    }

    NSLog(@"Operation completed");
}

in the drawRect method of the customView I have

- (void)drawRect {

    <<Drawing code>>

    NSLog(@"Drawed");
    delegate.drawedViews++;

    if (delegate.drawedViews==VIEWS_NUMBER) {
        [delegate allViewsDrawn];
    }
}

So the delegate get the notification when all the views are drawn.

The problem is that after the “Operation completed” log it takes about 5 seconds before I can see the first “Drawed” log.

Why is this happening? And generally speaking, how should I behave in order to find out which line of code is taking so much time being executed?

—— EDIT ——

Sometimes (like 1 out of 10 times) I was getting crashes doing this because I shouldn’t call addsubview from the NSOperation since it is not thread-safe. So I changed it to:

[delegate.view  performSelectorOnMainThread:@selector(addSubview:) withObject:customView waitUntilDone:NO];

Now I don’t have crashes anymore, but the process takes a very long time to be executed! Like 5 times more than before.

Why is it so slow?

  • 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-04T15:25:21+00:00Added an answer on June 4, 2026 at 3:25 pm

    To make things work properly we need to forget about NSOperation and use this “trick”

    dispatch_queue_t main_queue = dispatch_get_main_queue();
    dispatch_async(main_queue, ^{
    
        [self createCustomViews];
    
        dispatch_async(main_queue, ^{
    
            [self addAnotherCustomViewToView];
    
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented custom errors in my asp.net mvc application by following this article
i have implemented following method in my application. - (void)accelerometer:(UIAccelerometer *)acel didAccelerate:(UIAcceleration *)aceler {
I have implemented the following set up (after being requested): slideshow of images changing,
I have the following tricky problem: I have implemented a (rather complicated) class which
I have the following problem: I implemented a managed mobile application for Windows Mobile
I have the following Strategy Pattern implemented: public abstract class RetrievalStrategy { public abstract
I have the following problem. I have a tabbed application implemented using a ViewPager.
In my project I have the following three interfaces, which are implemented by classes
I have an Android Activity with a RelativeLayout and I have implemented the following
Hey you guys (and girls), I have implemented the following CSS: #tab-navigation ul li:last-child

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.