关于系统自带的下拉刷新

来源:互联网 发布:mac 查看命令路径 编辑:程序博客网 时间:2024/05/01 07:21

我们平时一般都是用第三方的下拉刷新,但是我发现系统的下拉效果也不错,而且性能还非常高,系统的调用起来非常简单,直接上代码:

- (void)viewDidLoad{    [super viewDidLoad];    array = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4", nil];        self.refreshControl = [[UIRefreshControl alloc] init];    //加上这句会导致整个TableView下移,所以不要添加。//    self.refreshControl.attributedTitle=[[NSAttributedString alloc]initWithString:@"下拉刷新"];    [self.refreshControl addTarget:self action:@selector(doRefresh:) forControlEvents:UIControlEventValueChanged];}-(void)doRefresh:(id)sender{        NSLog(@"refresh");    self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"刷新中"];    [self performSelector:@selector(endRefreshing) withObject:nil afterDelay:2];}- (void) endRefreshing{    NSLog(@"refreshed");    [self.refreshControl endRefreshing];    self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"];    [self.tableView reloadData];}


下面是可以实现加载更多效果:

 /******自定义查看更多属性设置******/    _bottomRefresh = [UIButton buttonWithType:UIButtonTypeCustom];    [_bottomRefresh setTitle:@"查看更多" forState:UIControlStateNormal];    [_bottomRefresh setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];    [_bottomRefresh setContentEdgeInsets:UIEdgeInsetsMake(15, 0, 0, 0)];    [_bottomRefresh addTarget:self action:@selector(upToRefresh) forControlEvents:UIControlEventTouchUpInside];    _bottomRefresh.frame = CGRectMake(0, 44+_rowCount*RCellHeight, 320, RCellHeight);    [self.tableView addSubview:_bottomRefresh];

0 0