无标题文章

```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;

}

```

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 【2017年最新】☞ iOS面试题及答案 设计模式是什么? 你知道哪些设计模式,并简要叙述? 设计模式是一种编码经...
    紫色冰雨阅读 621评论 0 1
  • //// AddressBookViewController.h// QRCodeScanApp//// Crea...
    奇怪的知识增加了阅读 318评论 0 0
  • 在八十年代供销社是城乡联络的纽带。工业品下乡,农产品进城,都通过供销社。有生产门市部,副食门市部,书店文具门市部,...
    Jane漂漂阅读 3,406评论 27 32
  • 让一下。..噗 明明对老王说的,在电梯里,结果另一个男的懵逼的给我让了路。 看了栅岚给的书《就喜欢你讨厌我又干不掉...
    只是找一个地方码子_阅读 258评论 0 0
  • 最后一次决定诀别的夜晚,我看到我和你走到了高楼的天台,广阔,突然感觉到自身的渺小有融入那广阔视野的冲动,你牵起我,...
    茆茆2B阅读 535评论 2 7