1.相关代码
- (void)viewDidLoad {
[superviewDidLoad];
//初始化变量和时间
self.Logs = [[NSMutableArrayalloc]init];
NSDate *date = [[NSDatealloc]init];
[self.LogsaddObject:date];
//初始化UIRefreshControl
UIRefreshControl *rc = [[UIRefreshControlalloc]init];
rc.attributedTitle = [[NSAttributedStringalloc]initWithString:@"下拉刷新"];
[rc addTarget:selfaction:@selector(refreshTableView)forControlEvents:UIControlEventValueChanged];
self.refreshControl = rc;
}
-(void) refreshTableView {
if (self.refreshControl.refreshing) {
self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"加载中..."];
//添加新的模拟数据
NSDate *date = [[NSDatealloc]init];
[self.LogsaddObject:date];
[self.refreshControlendRefreshing];
self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"];
[self.tableViewreloadData];
}
}
2.下拉刷新控件 UIRefreshControl只能应用于表视图界面,而且根视图控制器必须是表视图控制器UITableViewController,不能是其他视图控制器。