uitableView 自带的刷新控件

uitableView 自带刷新控件,只需几行代码轻松搞定上拉刷新

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

   NSAttributedString * title = [[NSAttributedString alloc]initWithString:@"刷新"];

    refresh.attributedTitle = title;

    refresh.tintColor = [UIColor grayColor];

    self.refresh = refresh;

    [refresh addTarget:self action:@selector(refreshAction) forControlEvents:(UIControlEventValueChanged)];

    [tableView addSubview:refresh];



#pragma mark - 刷新

- (void)refreshAction{

    NSAttributedString * title = [[NSAttributedString alloc]initWithString:@"加载。。。。"];

    self.refresh.attributedTitle = title;

     //刷新
    [self performSelector:@selector(myBrokeFinishRefresh) withObject:nil afterDelay:2.0];

}


- (void)myBrokeFinishRefresh{
    [currentRefreshCrtl endRefreshing];
    NSAttributedString * refreshCtrl = [[NSAttributedString alloc]initWithString:@"下拉刷新"];
    currentRefreshCrtl.attributedTitle = refreshCtrl;
    
}

你可能感兴趣的:(ios,xcode,控件,UITableView)