你好,歡迎來到IOS教程網

 Ios教程網 >> IOS訊息 >> 關於IOS >> 處理彈出很多提示框

處理彈出很多提示框

編輯:關於IOS

如果我們有一個界面有很多請求,但這時候所有的請求都無效,這是我們可能會提示用戶 “請求失敗”,“請求超時“等等,

如果提示一次那當然很好,但是每一個失敗的請求都觸發一次提示框來提示用戶,這樣會很糟糕。 可能一次彈出很多提示框,我們點擊一次然後又彈出另一個,並且這些提示信息還是一樣的,這樣會讓用戶很惱火的。   假設某家公司有兩個不同的數據庫A 和B,但是A是內網的,B是現網的,我們在A中注冊下,然後把信息保存,這時候我們修改地址指向B,可能會出現問題。 如果我們訪問了需要提供access token 的資源,我們需要提供access token ,但是這個access token 在A中是有效的,在B中是無效的。 所以服務端可能會返回 “無效的access token”等。 可是我們已經登陸了啊,咋辦呢? 我們可以根據具體的情況,重新彈出登陸界面,當然這只是一個例子,我們可以用這樣的方法處理其他類似的情況。   1  用dispatch once 這個不說了 2  用工廠類方法 #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=@"登陸";          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  
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved