是否可以UIRefreshControl
在启动应用程序时自动启动?我试过打电话self.refreshControl beginRefreshing];
,但它不工作。
这是我的 viewDidLoad 中的一些代码:
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(refreshNowShowingMoviesList:) forControlEvents:UIControlEventValueChanged];
[self setRefreshControl:refreshControl];
[refreshControl beginRefreshing];
编辑
这是我的 refreshNowShowingMoviesList 方法:
- (void)refreshNowShowingMoviesList:(id)sender
{
// Create URL
NSURL *url = [NSURL URLWithString:kNowShowingMoviesURL"];
// Initialize URL request
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
// Set value on header
[urlRequest setValue:kHeaderFieldValue forHTTPHeaderField:kHeaderField];
// JSON request operation
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:urlRequest success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSMutableArray *results = [(NSDictionary *)JSON objectForKey:@"results"];
if ([results count]) {
_objects = results;
// Reload table view
[self.tableView reloadData];
// End refreshing
[(UIRefreshControl *)sender endRefreshing];
}
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
// End refreshing
[(UIRefreshControl *)sender endRefreshing];
// Show error alert
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:kSorryTitle message:[error localizedDescription] delegate:self cancelButtonTitle:nil otherButtonTitles:kOk, nil];
[errorAlert show];
});
}];
// Start operation
[operation start];
}
带有错误消息:
'NSInvalidArgumentException', reason: '-[MasterViewController endRefreshing]: unrecognized selector sent to instance 0xa172450'