0

我有一个tableviewwith 响应detialview。在detailview我有一些从 URL 加载的图像和标签。我正在尝试向UIActivityindicatorview单元格添加一个以显示正在加载。我已经处理过了,但它显示到很晚并且当我回到tableview. 我到处寻找一个简单的解决方案,但失败了......

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {

ReaDetailViewController *reaDetail = [[ReaDetailViewController alloc] initWithNibName:@"ReaDetailViewController" bundle:nil];

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

UIActivityIndicatorView *activityView = 
[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[activityView startAnimating];
[cell setAccessoryView:activityView];
[activityView release];

[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];

    { 
    reaDetail.petImageString = [[NSString alloc] initWithString:[[exclusiveArray objectAtIndex:indexPath.row] objectForKey:@"image"]]; 

    reaDetail.petLabelString = [[NSString alloc] initWithString:[[exclusiveArray objectAtIndex:indexPath.row] objectForKey:@"description"]]; 

    reaDetail.petLabelString1 = [[NSString alloc] initWithString:[[exclusiveArray objectAtIndex:indexPath.row] objectForKey:@"description1"]]; 

    reaDetail.petLabelString2 = [[NSString alloc] initWithString:[[exclusiveArray objectAtIndex:indexPath.row] objectForKey:@"description2"]]; 





    reaDetail.title = [[exclusiveArray objectAtIndex:indexPath.row] objectForKey:@"name"]; 
}


// Pass the selected object to the new view controller.
[self.navigationController pushViewController:reaDetail animated:YES];
[reaDetail release];


   }

任何帮助都非常有帮助!

4

1 回答 1

0

我了解您希望在加载视图控制器时使活动视图具有动画效果。问题是在您从该选择方法返回之前,活动视图不会开始动画......这大约是您的控制器准备好被推送的时间。

然后有2个选项:

  • 您可以尽快退出该方法,调用perfomSelector:onMainThread以执行要推送的视图控制器的初始化步骤
  • 或者更好的是,尽快推送视图控制器,并在此控制器的viewDidLoadviewWillAppear方法中执行其初始化过程(您可以在此新视图中添加活动控制器)。

如果您选择第一个选项,您应该deselectRowAtIndexPath在推送新的视图控制器后调用该方法,并stopAnimating从此deselectRowAtIndexPath方法调用指示器视图。

于 2011-11-23T22:21:44.010 回答