简体   繁体   中英

How can I get my loading label to show up when I click button to next view controller?

I have attached the UIButton to a method for when it is pressed:

- (IBAction)searchButtonPressed:(id)sender
{
    NSLog(@"Search button pressed");
    self.loadingLabel.hidden = false;
}

The problem is that when I click on the search button it is pausing for a few seconds (the button does that pressed down effect), however I want to put up a loading screen (as a UILabel) instead of this so the user knows what is happening. My searchButtonPressed method does not work for making the loadingLabel visible. The UIButton opens another view controller when pressed which contains a NSScanner that is parsing through some text. This is what is causing the delay (it takes a few seconds before the next view controller is actually visible). How can I display a loading screen (as UILabel) when switching from one view controller to another while it is in process of taking care of the viewdidload in next view controller? I think that the view controller does not actually show until the viewdidload of that view controller is completed. Thank you.

move your NSScanner to backgound in viedDidload or bring it to - (void)viewDidAppear:(BOOL)animated (in backgound).

Show a loading view in navigationController view when press button in previous view, set tag for this loading view

When task is completed go to main thread to reload view and hide this loading view (can get it by tag)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM