2

我正在寫執行與AFNetworking框架HTTP請求的應用程序,數據收到得到解析,然後放入表視圖活動指示器的動畫僅一次

我已經創建與裝載機特殊細胞,這表明當請求正在處理中。這個單元格只有一個.xib文件,沒有自定義類。 我在此單元格內添加了活動指示器,並在屬性檢查器中選中了「動畫」選項。

而且我已經創建BOOL伊娃顯示該單元格。

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

+0

哪裏是你的起點和停止activiindicator代碼? – Rajneesh071 2013-03-15 17:30:25

+0

@ Rajneesh071我有沒有代碼,因爲我選擇的行爲:在屬性檢查器中爲活動指示燈動畫,所以必須動畫所有的時間在任何條件下 – Dudeson 2013-03-20 10:30:40

+0

發送您的示例代碼... – Rajneesh071 2013-03-20 11:29:28

回答

2

當你停止動畫和隱藏單元格的截圖在這裏,它不是去分配。這意味着下次您加載單元格時,它將採用與隱藏時相同的狀態。加載單元格後,您需要撥打[activityView startAnimating];

+0

也許有辦法訪問此屬性,而不創建該單元格的自定義類,現在我只有該單元格的xib文件 – Dudeson 2013-03-20 10:55:33

+0

找到了一種方法!我用標記標記了它,並通過'ViewWithTag:'來訪問它。'現在它動畫所有的時間,謝謝! – Dudeson 2013-03-20 11:11:47

0

一旦嘗試這樣的,在的tableView willDisplayCell:方法隱藏,而不是JSONRequestOperationWithRequest後提醒:像下面sucess方法,

-(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; 
} 

希望它會幫助你...

+0

我試過了,它沒有幫助 – Dudeson 2013-03-20 10:54:37