PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 18, 2022

[FIXED] How to reduce the initial time to show loader?

 July 18, 2022     gif, ios7, loader, nstimer, xcode5     No comments   

Issue

I am implementing loader in button action , but when i click on button it takes 3 to 5 sec to start loading. i am using two controller to implement loader- UIImage+animatedGIF.h to use gif image and MBProgressHUD.h to implement progress time. i don't know how to reduce the initial time that takes to start loader. I am using this code to implement loader-

NSURL *url = [[NSBundle mainBundle] URLForResource:@"loadingg" withExtension:@"gif"];

    self.loader.image = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url]];


    float progress = 0.0f;

    while (progress < 1.0f) {



        progress += 0.01f;

       // HUD.progress = progress;

        usleep(50000);


    }

    [NSTimer scheduledTimerWithTimeInterval:progress target:self selector:@selector(abcd) userInfo:nil repeats:NO];     

Solution

I must assume that usleep(50000) is not on the main thread.

If it is, there is your 5 secs delay. Sleeping the main thread does just that: wait. The right approach is an asynchronous load.

Read @bbum recommendation for when it's appropriate to invoke usleep: what is the difference among sleep() , usleep() & [NSThread sleepForTimeInterval:]?



Answered By - SwiftArchitect
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing