iOS iOS Developer

从零开始设计搭建ios App框架(四)

2016-09-25  本文已影响291人  潇水渔翁

错误提示页面


大家开发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添加消息提示框
下一节:下拉刷新

上一篇 下一篇

猜你喜欢

热点阅读