2

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

4

2 に答える 2

2

アニメーションを停止してセルを非表示にしても、割り当ては解除されません。これは、次にセルをロードしたときに、非表示のときと同じ状態になることを意味します。[activityView startAnimating];セルをロードした後に呼び出す必要があります。

于 2013-03-15T16:59:44.220 に答える
0

このように試してみると、以下のようなJSONRequestOperationWithRequest:successメソッドの後ではなく、tableView willDisplayCell:methodでアラートを非表示にします。

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
//hide your alert,i think in your case isLoading = NO to hide alert so,
isLoading = NO;
}

それがあなたを助けることを願っています...

于 2013-03-16T13:09:06.137 に答える