iOS UITableView(十一) tableView的下拉刷新
来源:互联网 发布:电脑软件助手下载 编辑:程序博客网 时间:2024/05/27 21:50
如今下拉刷新有常用的几个第三方用着也不错,这里我用系统的UIRefreshControl来给大家介绍一下系统的刷新,注意此控件目前只能用于UITableViewController,大家用的时候注意。第三方择没有限制
下面我给大家展示一下代码(还是用的上次的索引Demo)
// ViewController.m// UItableViewIndexes//// Created by SPF on 16/1/6.// Copyright (c) 2016年 SPF. All rights reserved.//#import "ViewController.h"@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>{ UITableView *_tableView; NSMutableArray *_dataArr; UIRefreshControl *_refresh; NSMutableArray *_timeArry;}@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self creatData]; _timeArry=[[NSMutableArray alloc]init]; _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped]; _tableView.delegate=self; _tableView.dataSource=self; [self.view addSubview:_tableView]; [self creatRefresh];}-(void)creatRefresh{ _refresh=[[UIRefreshControl alloc]init]; //刷新图形颜色 _refresh.tintColor=[UIColor orangeColor]; //刷新的标题 _refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"下拉刷新"]; // UIRefreshControl 会触发一个UIControlEventValueChanged事件,通过监听这个事件,我们就可以进行类似数据请求的操作了 [_refresh addTarget:self action:@selector(refreshTableviewAction:) forControlEvents:UIControlEventValueChanged]; //UIRefreshControl目前只能用于UITableViewController self.refreshControl =_refresh;}-(void)refreshTableviewAction:(UIRefreshControl *)refreshs{ if (refreshs.refreshing) { refreshs.attributedTitle = [[NSAttributedString alloc]initWithString:@"正在刷新"]; [self performSelector:@selector(refershData) withObject:nil afterDelay:2]; }}-(void)refershData{ NSString *syseTiem = nil; NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; //创建的时间格式 syseTiem = [formatter stringFromDate:[NSDate date]]; NSString *lastUpdated = [NSString stringWithFormat:@"上一次更新时间为 %@", [formatter stringFromDate:[NSDate date]]]; self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:lastUpdated] ; [_timeArry addObject:syseTiem]; [self.refreshControl endRefreshing]; [_tableView reloadData]; }-(void)creatData{ _dataArr=[[NSMutableArray alloc]init]; for (int i=0; i<26; i++) { NSMutableArray *arr=[[NSMutableArray alloc]init]; for (int j=0; j<10; j++) { NSString *str=[NSString stringWithFormat:@"这是第%c组的第%d个标题",'A'+i,j]; [arr addObject:str]; } [_dataArr addObject:arr]; }}#pragma mark -表格索引//返回右侧索引标题数组//这个标题的内容时和分区标题相对应-(NSArray*)sectionIndexTitlesForTableView:(UITableView *)tableView{ NSMutableArray *arr=[[NSMutableArray alloc]init]; //创建26个索引标题 //标题尽量和分区相对应 [arr addObject:UITableViewIndexSearch]; for (int i = 0; i < 26; i++) { NSString *str = [NSString stringWithFormat:@"%c",'A'+i]; [arr addObject:str]; } return arr;}//设置 右侧索引标题 对应的分区索引- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { //cell右侧标题 NSLog(@"title:%@",title); //右侧标题在右侧的索引 NSLog(@"index:%ld",index); //返回 对应的分区索引 return index-1;}//cell 内容的向右缩进 级别- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath { return 1;}#pragma mark uitableView代理//返回多少组-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return _dataArr.count;}//每个分区有多少行-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [_dataArr[section] count];}-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //创建复用标识符 static NSString *cellID =@"cellID"; UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID]; } //填充cell cell.textLabel.text=_dataArr[indexPath.section][indexPath.row]; return cell;}//设置头标-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return [NSString stringWithFormat:@"这是第%c组",'A'+section];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
我是为了演示效果将前面的继承改为下面这样,大家将来写的时候若想用系统的记得只能用于UITableViewController
#import <UIKit/UIKit.h>@interface ViewController : UITableViewController@end其它的第三方我有时间再为大家介绍
0 0
- iOS UITableView(十一) tableView的下拉刷新
- ios tableView那些事 (十七) UITableView的下拉刷新
- iOS UITableView的下拉刷新
- IOS UITableView下拉刷新
- iOS tableView 自带的下拉刷新
- ios:UITableView下拉刷新的使用
- iOS UITableView(十一) tableView的几个小技巧
- IOS控件TableView下拉刷新
- iOS开发之UITableView的下拉刷新实现
- iOS开发>>>UITableView下拉刷新控件的使用
- IOS怎么实现一个UITableView的下拉刷新
- iOS之UITableView的使用—下拉刷新
- UITableView下拉刷新的使用
- UItableview的下拉刷新实现
- IOS小技巧-tableview下拉刷新
- IOS控件 Tableview 下拉刷新,加载数据
- IOS控件 Tableview 下拉刷新,加载数据
- IOS UITableView下拉刷新(转)
- Android中的Http请求
- Android内核之Context
- [搬运] 三层界面布局实例展示
- JavaScript的那些坑之事件代理
- ORACLE 10G的数据泵自动备份脚本
- iOS UITableView(十一) tableView的下拉刷新
- skyline代码搬迁后3d控件出错
- 关于智能时代革命性产品的构想--虚拟机器人
- 多益网址——开发者专用
- JAVA中实现链式操作(方法链)的简单例子
- 如何搭建一个自己的网络验证系统?
- caffe深度学习系列2015年12月
- JAVASE之泛型
- Adaboost的几个人脸检测网站