zoukankan      html  css  js  c++  java
  • 表视图UI设计模式

    俩个UI设计模式:分页模式和下拉刷新模式

    1.分页模式

    当数据量很大时,一次返回所有的信息这种方式严重影响应用的性能,造成网络堵塞。通常我们利用分页模式来解决请求大量数据的问题。分页模式是先请求少量数据,例如一次50条,当翻动屏幕已显示50条数据后,应用会再次请求50条。根据触发方式的不同,请求分为主动请求和被动请求。主动请求模式,即当条件满足时,再次请求下50条数据是自动发出的,并且一般在表视图的表脚会出现活动指示器,请求结束后活动指示器会隐藏起来。被动请求模式,当条件满足是,表视图的表脚中会出现一个响应点击事件的控件,这个控件一般是一个按钮,按钮标签一般会设为“更多”,当点击“更多”按钮时,应用会向服务器请求,请求结束后“更多”按钮会隐藏起来。

    2.下拉刷新模式

    下拉刷新是重新刷新表视图或列表,以便重新加载数据。下拉刷新与分页相反,当翻动屏幕到顶部时,在往下拉屏幕,程序就开始重新请求数据,此时表视图的表头部分会出现活动指示器,请求结束后表头消失。

    @interface ViewController : UITableViewController<UITableViewDataSource,UITableViewDelegate>

    @property(nonatomic,strong)NSMutableArray *logs;

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view, typically from a nib.

        self.logs = [[NSMutableArray alloc]init];

        NSDate *date = [[NSDate alloc]init];

        [self.logs addObject:date];

        

        UIRefreshControl *rc = [[UIRefreshControl alloc]init];

        rc.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"];

        [rc addTarget:self action:@selector(refreshTableView) forControlEvents:UIControlEventValueChanged];

        self.refreshControl = rc;

    }

    -(void)refreshTableView

    {

        if(self.refreshControl.refreshing){

            self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"加载中..."];

            

            NSDate *date = [[NSDate alloc]init];

            [self performSelector:@selector(callBackMethod:) withObject:date afterDelay:3];

        }

    }

    -(void)callBackMethod:(id)obj

    {

        [self.refreshControl endRefreshing];

        self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"];

        [self.logs addObject:(NSDate*)obj];

        [self.tableView reloadData];

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    #pragma mark - UITableViewDataSource

    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

        return 1;

    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

        return [self.logs count];

    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    {

        static NSString *cellIndentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];

        if (cell == nil) {

            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIndentifier];

        }

        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];

        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss zzz"];

        cell.textLabel.text = [dateFormatter stringFromDate:[self.logs objectAtIndex:indexPath.row ]];

        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        return cell;

    }

    @end

  • 相关阅读:
    sessionStorage 前端HTML5会话管理
    html多文件上传,可支持预览
    com.alibaba.druid.pool.DruidDataSource : {dataSource2} init error
    MybatisPlus 3.0代码生成器
    Node.js、npm、vuecli 的安装配置环境变量
    vuecli +echartsamap集成echarts和高德地图TypeError: Cannot read property 'dataToPoint' of null解决方案
    SpringBoot2.0+MybatisPlus3.0+Druid1.1.10 一站式整合
    MySQL DATE_FORMAT函数使用
    shiro使用redis作为缓存,出现要清除缓存时报错 java.lang.Exception: Failed to deserialize at org.crazycake.shiro.SerializeUtils.deserialize(SerializeUtils.java:41) ~[shiroredis2.4.2.1RELEASE.jar:na]
    【接口时序】4、SPI总线的原理与Verilog实现
  • 原文地址:https://www.cnblogs.com/PJXWang/p/5465123.html
Copyright © 2011-2022 走看看