I'm trying to implement UIRefreshControl in a UIViewController. I can't use UITableViewController because the tableView is just one segment of my viewController.
In most cases this workaround works like charm. But sometimes (random occurrence) the app crashes with EXC_BAD_ACCESS code=1
- (void)viewDidLoad {
[super viewDidLoad];
UIRefreshControl * refCon = [[UIRefreshControl alloc] init];
[refCon addTarget:self selector:@selector(refresh:) forControlEvent:UIControlEventValueChanged];
[tableView addSubView:refCon];
}
- (void)refresh:(UIRefreshControl *)sender {
[NSThred detachNewThreadSelector:@selector(doRefresh:) toTarget:self withObject:sender];
}
- (void)doRefresh:(UIRefreshControl *)sender {
[self checkUpdate];
[self loadData];
[sender endRefreshing];
}
You're invoking -endRefreshing
on a background thread. Don't do that.
And also, adding a UIRefreshControl
directly as a subview of UITableView
is not guaranteed to work. You should be using a UITableViewController
.