iOS表视图下拉刷新与索引

下拉刷新
创建UIRefreshControl的实例,将其赋给TableViewController的refreshControl属性,为控件添加valueChanged事件监听,在事件响应中,判断控件的状态,决定做的事情,最后再将控件改成停止刷新状态
1.配置下拉刷新功能
UIRefreshControl *rc = [[UIRefreshControl alloc]init];
[rc addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
2.刷新界面 在refresh中执行 要被传入刷新控件 参数不能为空
if ([rc isRefreshing]) {// 正在旋转
// 发网络请求,读取新数据
// 当数据接收完毕后,通知系统刷新界面
// 4秒钟后,将网络发回得abc这个数据
// 传递给refreshOver这个方法
// 由这个方法来刷新界面
[self performSelector:@selector(refreshOver:) withObject:@”abc” afterDelay:4];
}

3.结束刷新状态
//result参数就是 withObject中传来的“abc”
-(void)refreshOver:(NSString *)result
{
//先改数据模型
[self.allStr insertObject:result atIndex:0];
//将abc显示到表格中
NSIndexPath *t1 = [NSIndexPath indexPathForRow:0 inSection:0];
NSIndexPath *t2 = [NSIndexPath indexPathForRow:0 inSection:1];
NSIndexPath *t3 = [NSIndexPath indexPathForRow:0 inSection:2];
NSIndexPath *t4 = [NSIndexPath indexPathForRow:0 inSection:3];
[self.tableView insertRowsAtIndexPaths:@[t1,t2,t3,t4] withRowAnimation:UITableViewRowAnimationAutomatic];
//修改refreshControl为结束刷新状态
[self.refreshControl endRefreshing];
}

索引
多分区的情况下,先设置每个分区的分区头,再实现sectionIndexTitlesForTableView,返回出现在索引位置上的文字,返回的标题的个数与分区数相同,按顺序,第一个标题就与第一个分区关联,最后一个标题就与最后一个分区关联
设置索引标题内容
- (NSArray )sectionIndexTitlesForTableView:(UITableView )tableView
{
return @[@”A”,@”B”,@”C”,@”D”];
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值