用惯了MJRefresh, EGOTableViewRefresh, 最近项目用UIRefreshControl尝试了下下拉刷新,也挺好的。。
@interface DeviceHomePageViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) UITableView *myTableView;
@property (strong, nonatomic) UIRefreshControl *refreshControl;
- (void)viewDidLoad {
[super viewDidLoad];
self.automaticallyAdjustsScrollViewInsets = NO;
//创建self.myTableView
//*************//
//给tableview加refreshControl
[self setUpRefreshControl];
[self.myTableView addSubview:self.refreshControl];
}
#pragma mark - UIRefreshControl
- (void)setUpRefreshControl {
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self
action:@selector(refreshEventValueChanged:)
forControlEvents:UIControlEventValueChanged];
[self.refreshControl setTintColor:[UIColor colorWithRed:130 / 255.0 green:190 / 255.0 blue:250 / 255.0 alpha:1]];//自定义颜色
}
- (void)refreshEventValueChanged:(UIRefreshControl *)refreshControl {
//重新调用获取设备接口
[self.refreshControl beginRefreshing];
[SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeClear];
//调用接口 重新加载数据
[[SGDataManager sgDataManager].devicesManager getDevices:^(BOOL result, NSError * error, id object) {
[self.myTableView reloadData];
}];
[SVProgressHUD dismiss];
[self.refreshControl endRefreshing];
}
#pragma mark