錯誤提示頁面
大家開發(fā)app時有沒有遇到網(wǎng)絡(luò)加載數(shù)據(jù)時出錯顯示提示頁面,當請求結(jié)果是沒有數(shù)據(jù)時(不是網(wǎng)絡(luò)出錯)給出無數(shù)據(jù)的提示頁面。這些情況如果沒有提示頁面,界面空白,用戶的體驗不是很好。
而這些案例的產(chǎn)生大部分是發(fā)生在Controller上,所以為了使用方便,我們在BaseController添加如下幾個方法:
#pragma mark errorView
- (void)showErrorView:(UIView *)pView flag:(NSString *)viewFlag errorView:(UIView * (^)(void))errorView;
- (void)hideErrorView:(UIView *)pView flag:(NSString *)viewFlag;
- (void)hideErrorView:(NSString *)viewFlag;
而一個App的為了保持風格統(tǒng)一,同一種情況的提示頁面都是一樣的。因此為BaseController擴展一個分類:
@interface PGBaseController (errorView)
/**
數(shù)據(jù)加載出錯時顯示提示頁面
*/
- (void)showDataLoadErrorView;
/**
隱藏提示頁面
*/
- (void)hideDataLoadErrorView;
/**
沒有數(shù)據(jù)時
*/
- (void)showNoDataView;
- (void)hideNoDataRecordView;
@end
這個時候調(diào)用就很方便了,再需要的地方一句簡單代碼就可以了。
數(shù)據(jù)出錯時:
[self showDataLoadErrorView];
[self hideDataLoadErrorView];
無數(shù)據(jù)時:
[self showNoDataView];
[self hideNoDataRecordView];
其實也不排除有特殊的頁面提示,這個時候就得這樣實現(xiàn)了:
WEAKSELF
[self showErrorView:self.view flag:@"errorView" errorView:^UIView *{
CGFloat y = weakSelf.nNavMaxY;
CGFloat h = weakSelf.view.frame.size.height-y;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, y, weakSelf.viewWidth, h)];
view.backgroundColor = weakSelf.view.backgroundColor;
UILabel *label = [PGUIKitUtil createLabel:@"根據(jù)業(yè)務(wù)自定義頁面" frame:CGRectMake(PGHeightWith1080(30), y, weakSelf.viewWidth-2*PGHeightWith1080(30), PGHeightWith1080(80)) bgColor:view.backgroundColor titleColor:[UIColor blackColor] font:[PGUIKitUtil systemFontOfSize:13] alignment:NSTextAlignmentCenter];
[view addSubview:label];
label.center = view.center;
return view;
}];
//隱藏
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self hideErrorView:self.view flag:@"errorView"];
});
帖個效果圖出來
608619CF-6ED2-409E-87BE-AADA4B20F6CD.png
上一節(jié):為App添加消息提示框
下一節(jié):下拉刷新