self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:self.tableView];
[self.tableView registerClass:[MyTableViewCell class] forCellReuseIdentifier:cellId];
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.tintColor = [UIColor grayColor];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@""];
[refreshControl addTarget:self action:@selector(refreshAction) forControlEvents:UIControlEventValueChanged];
self.tableView.refreshControl = refreshControl;
-(void)refreshAction {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.tableView.refreshControl endRefreshing];
});
}
ios 10之前只对UITableviewController使用,ios 10之后支持 UIScrollView 以及其子类,比如说 UICollectionView,UITableView。