錯誤提示頁面
大家開發app時有沒有遇到網絡加載數據時出錯顯示提示頁面,當請求結果是沒有數據時(不是網絡出錯)給出無數據的提示頁面。這些情況如果沒有提示頁面,界面空白,用戶的體驗不是很好。
而這些案例的產生大部分是發生在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的為了保持風格統一,同一種情況的提示頁面都是一樣的。因此為BaseController擴展一個分類:
@interface PGBaseController (errorView)
/**
數據加載出錯時顯示提示頁面
*/
- (void)showDataLoadErrorView;
/**
隱藏提示頁面
*/
- (void)hideDataLoadErrorView;
/**
沒有數據時
*/
- (void)showNoDataView;
- (void)hideNoDataRecordView;
@end
這個時候調用就很方便了,再需要的地方一句簡單代碼就可以了。
數據出錯時:
[self showDataLoadErrorView];
[self hideDataLoadErrorView];
無數據時:
[self showNoDataView];
[self hideNoDataRecordView];
其實也不排除有特殊的頁面提示,這個時候就得這樣實現了:
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:@"根據業務自定義頁面" 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
上一節:為App添加消息提示框
下一節:下拉刷新