首页 > 系统 > iOS > 正文

iOS UIRefreshControl

2019-11-09 16:05:42
字体:
来源:转载
供稿:网友
#import "RefreshViewController.h"@interface RefreshViewController ()<UITableViewDelegate,UITableViewDataSource>@PRoperty (nonatomic, strong) UITableView *tableView;@property (nonatomic, strong) UIRefreshControl *refreshControl;@end@implementation RefreshViewController- (void)viewDidLoad { [super viewDidLoad]; _tableView = [[UITableView alloc] initWithFrame:self.view.bounds]; _tableView.delegate = self; _tableView.dataSource = self; [self.view addSubview:_tableView]; [self createRefreshControl];}- (void)createRefreshControl{ if (_refreshControl == nil) { _refreshControl = [[UIRefreshControl alloc] init]; [_refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged]; [self.tableView addSubview:_refreshControl]; } //默认进入刷新状态 [self refresh]; _tableView.contentOffset = CGPointMake(0, -60);}- (void)refresh{ [_refreshControl beginRefreshing]; [self performSelector:@selector(endRefresh) withObject:nil afterDelay:3.0f];}- (void)endRefresh{ [_refreshControl endRefreshing]; _tableView.contentOffset = CGPointMake(0, 0);}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 10;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; } cell.textLabel.text = @"测试数据"; return cell;}@end

这里写图片描述


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表