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