處理彈出很多提示框

來源:互聯網
上載者:User

如果我們有一個介面有很多請求,但這時候所有的請求都無效,這是我們可能會提示使用者 “請求失敗”,“請求逾時“等等,如果提示一次那當然很好,但是每一個失敗的請求都觸發一次提示框來提示使用者,這樣會很糟糕。可能一次彈出很多提示框,我們點擊一次然後又彈出另一個,並且這些提示資訊還是一樣的,這樣會讓使用者很惱火的。 假設某家公司有兩個不同的資料庫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 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.