Best way to show loading screen in iPhone app?

I am creating what is essentially a web application. Each piece of data must be retrieved from the web API. That way, every UITableView I show takes some time to fill in the data, and I'm struggling to find a good way to show the user a loading screen.

Now I am popping up an action sheet, but that seems a bit wrong. Ideally, I would open an empty view above the table view with β€œLoading ...” on it, and then disappear when the data arrives, but I cannot think of a way to do this in 8 places in my application without massive code duplication.

+4
source share
2 answers

for me there are two options.

  • Use alertview
  • Use MBProgressHUD.

  • For alertView, you must put the UIAlertView variable in the .h file. Then put the following code - when you request / load data.

    av=[[UIAlertView alloc] initWithTitle:@"Loading Data" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    ActInd=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [ActInd startAnimating];
    [ActInd setFrame:CGRectMake(125, 60, 37, 37)];
    [av addSubview:ActInd];
    [av show];

Now, after processing is complete, place the following statement.

[av dismissWithClickedButtonIndex:0 animated:YES];
[av release]; av=nil;

  • Another way: MBProgressHUD
  • This is very useful and ready for you - you just need to follow these steps.

  • Download it from the specified link
  • Import both files into your project (copy no link)
  • #import "MBProgressHUD.h" - import this when you want to use the progress view.
  • MBProgressHUD *mbProcess; - declare a variable in the * .h file.
  • Put the following code during processing (in the * .m file)

mbProcess=[[MBProgressHUD alloc] initWithView:self.view];
mbProcess.labelText=@ "Loading Data";
[self.view addSubview:mbProcess];
[mbProcess setDelegate:self];
[mbProcess show:YES];

  1. When your processing is complete, put this line. [mbProcess hide:YES];
  2. Do not forget to add the MBProgressHUD delegation method to your * .m file. like this

#pragma mark -
#pragma mark MBProgressHUDDelegate methods

 - (void)hudWasHidden { // Remove HUD from screen when the HUD was hidded [mbProcess removeFromSuperview]; [mbProcess release]; } 
+13
source

If you want a nice look, check out http://github.com/matej/MBProgressHUD

+6
source

Source: https://habr.com/ru/post/1306423/


All Articles