这里只介绍UIRefreshControl的使用方法,虽然EGO已经用得挺舒服的了,但是官方给的。毕竟还是蛮简单的
==================================================
UIRefreshControl 具有一个默认的高度和宽度
一旦创建,便自动管理。只有当用户用力刷新才能刷新,尤其。。。那朵菊花,用力越大,转速越快,感觉还不错哦。(瞬间。。。邪恶了)
下面介绍一下如何使用:
self.refreshControl = [[UIRefreshControl alloc] init]; self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"刷新中"]; [self.refreshControl addTarget:self action:@selector(insertNewObject:) forControlEvents:UIControlEventValueChanged]; [self.tableView addSubview:self.refreshControl];
- (void)insertNewObject:(id)sender { self.numberOfnewPosts = [self getRandomNumberBetween:0 to:4]; NSLog(@"%d new fetched objects",self.numberOfnewPosts); for(int i = 0; i < self.numberOfnewPosts; i++){ int addPost = [self getRandomNumberBetween:0 to:(int)([self.possibleTableData count]-1)]; [self.objects addObject:[self.possibleTableData objectAtIndex:addPost]]; } [self.refreshControl endRefreshing]; [self.tableView reloadData]; } -(int)getRandomNumberBetween:(int)from to:(int)to { return (int)from + arc4random() % (to-from+1); }