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

错误提示页面


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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,596评论 25 708
  • iOS网络架构讨论梳理整理中。。。 其实如果没有APIManager这一层是没法使用delegate的,毕竟多个单...
    yhtang阅读 5,259评论 1 23
  • 2016年11月27日 这几日,一直在思考“真实”,晚上枕着“真实”入眠。夜里头脑中出现十个大字,遗憾的是早上醒来...
    Indigolove阅读 156评论 0 0
  • 设置Hadoop用户export HADOOP_USER_NAME=jack创建Hadoop用户jack 只有设置...
    小甜瓜Melon阅读 1,202评论 0 0
  • 望上苍能帮我脱离苦海 望苦茶能练就我心智 望青莲能净化我心灵 望读书能埋葬我悲伤 望时间能断我相思苦 望流年能斩断...
    北漂流浪者阅读 211评论 0 0