If we have many requests on the interface, but all the requests are invalid at this time, we may prompt the user "request failed", "request timeout", etc, it would be nice to prompt once, but every failed request triggers a prompt box to prompt the user. This would be terrible. Many prompt boxes may pop up at a time. We click once and then bring up another one, and the prompt information is the same, which will make the user very angry. Assume that A company has two different databases, A and B, but A is on the Intranet and B is on the current network. Register in A and save the information, at this time, we can modify the address to point to B, which may cause problems. If we access the resource that requires access token, we need to provide access token, but this access token is valid in A and is invalid in B. Therefore, the server may return "invalid access token. But we have logged on. What should we do? We can re-bring up the login interface according to the specific situation. Of course this is just an example. We can use this method to handle other similar situations. 1. Use dispatch once. 2. Use the factory method # import <UIKit/UIKit. h> @ interface PresentLogInVC: UIViewController + (void) appearLogInVC; @ end # import "PresentLogInVC. h "static UINavigationController * _ navController; static PresentLogInVC * _ viewController; @ interface PresentLogInVC () {}@ end @ implementation PresentLogInVC + (void) appearLogInVC {if (! _ NavController) {_ viewController = [[self alloc] init]; _ navController = [[UINavigationController alloc] initWithRootViewController: _ viewController]; [_ viewController show];} else {NSLog (@ "have appeared !!! ") ;}}-(Void) show {UIWindow * window = [[[UIApplication sharedApplication] windows] objectAtIndex: 0]; [window addSubview: _ navController. view]; _ block CGRect r = [[UIScreen mainScreen] bounds]; r. origin. y = r. size. height; [_ navController. view setFrame: r]; [UIView animateWithDuration: 0.3 animations: ^ {r. origin. y = 0; www.2cto.com [_ navController. view setFrame: r];}-(void) dismiss {[UIView animateWithDuration: 0.3 animations: ^ {CGRect r = [[UIScreen mainScreen] bounds]; r. origin. y = r. size. height; [_ navController. view setFrame: r];} completion: ^ (BOOL B) {[_ navController. view removeFromSuperview];}-(void) viewDidLoad {[super viewDidLoad]; self. title = @ "login"; UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithTitle: @ "dismiss" style: UIBarButtonItemStyleDone target: self action: @ selector (dismiss)]; [self. navigationItem setLeftBarButtonItem: leftItem]; self. view. backgroundColor = [UIColor grayColor];}-(void) viewDidDisappear :( BOOL) animated {[super viewDidDisappear: animated]; [_ navController release]; _ navController = nil; [_ viewController release]; _ viewController = nil;} @ end