tableviewcell中的UIActivityIndi​​cator在加载detailview时显示较晚?

时间:2011-11-23 21:57:45

标签: iphone xcode android-activity uiactivityindicatorview didselectrowatindexpath

我有tableview回复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];


   }

任何帮助都非常有帮助!

1 个答案:

答案 0 :(得分:0)

我了解您希望在加载视图控制器时使活动视图变为动画。问题是,在您从此选择方法返回之前,活动视图不会开始动画...这是关于您的控制器准备好被推动的时间。

然后

2个选项:

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

如果选择第一个选项,则应在推动新视图控制器后调用deselectRowAtIndexPath方法,并使用此stopAnimating方法在指标视图上调用deselectRowAtIndexPath。< / p>