AFNetworking フレームワークで HTTP リクエストを実行するアプリを作成しています。受信したデータは解析され、テーブル ビューに配置されます。
ローダーを使用して特別なセルを作成しました。これは、リクエストが処理中であるときに表示されます。このセルには .xib ファイルのみがあり、カスタム クラスはありません。このセル内にアクティビティ インジケーターを追加し、属性インスペクターで [Animating] オプションをオンにしました。
また、このセルを表示するために BOOL ivar を作成しました。
BOOL isLoading;
「検索」ボタンがクリックされたときに実行される機能は次のとおりです。
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
if ([searchBar.text length] > 0){
isLoading = YES;
[self.tableView reloadData];
searchResults = [NSMutableArray arrayWithCapacity:10];
NSURL *url = [self urlWithSearchText:searchBar.text];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
[self parseDictionary:JSON];
[searchResults sortUsingSelector:@selector(compareName:)];
isLoading = NO;
[self.tableView reloadData];
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
[self showNetworkError];
isLoading = NO;
[self.tableView reloadData];
}];
[queue addOperation:operation];
}
}
そして、これが私がそのセルを取得する方法です
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (isLoading) {
return [tableView dequeueReusableCellWithIdentifier:LoadingCellIdentifier];
}
/*other code */
}
最初の検索を実行すると、このセルはアニメーション化されたアクティビティインジケーターで表示され、すべて問題ありませんが、他のすべての場合、このセルはスピンしないインジケーターで表示され、それが問題です。なぜこれが起こるのですか?他のすべての回で回転させるにはどうすればよいですか?
アプリのスクリーンショットhttp://monosnap.com/image/TRFK4cXEvYK2VPpteE1j5x0eB.png