Handling pop-up prompts

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.