```objc#import "ViewController.h"#import "IracleRefreshHeader.h"#define RandomData [NSString stringWithFormat:@"Never Have dreams come true %d ", arc4random_uniform(10000)]@interface ViewController ()@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_dataArray = [NSMutableArray array];
[self loadNewData];
_tableView.delegate = self;
_tableView.dataSource = self;
[self.view addSubview:_tableView];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
IracleRefreshHeader *headerView = [[IracleRefreshHeader alloc] initWithScrollView:_tableView];
__strong typeof(headerView) strongHeaderView = headerView;
__strong typeof(self) weakSelf = self;
headerView.RefreshBlock = ^(){
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf loadNewData];
[strongHeaderView endRefreshing];
});
};
}
- (void)loadNewData
{
for (int i = 0; i<5; i++) {
[_dataArray addObject:RandomData];
}
[_tableView reloadData];
}
#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdenttifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdenttifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdenttifier];
}
cell.textLabel.text = _dataArray[indexPath.row];
return cell;
}
```