加载详细视图时,tableviewcell 中的 UIActivityIndi​​cator 显示较晚?

发布于 2024-12-17 12:06:43 字数 1759 浏览 2 评论 0原文

我有一个带有响应的 tableviewdetialview。在 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];


   }

任何帮助都非常有帮助!

I have a tableview with responding detialview. In the detailview I have some images and labes that is loaded from a URL. I'm trying to add a UIActivityindicatorview to the cell to show that is loading. I have handled that but it shows up to late and does not disappear when I go back to the tableview. I have looked all over to find a simple solution, but failed...

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


   }

Any help is very helpful !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇女薄笑 2024-12-24 12:06:43

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

那么有两种选择:

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

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

I understand that you want to make the activity view to be animated while you load your view controller. The problem is the activity view won't start animating until you return from this selection method... which is about the time when your controller is ready to be pushed.

2 options then:

  • You could exit from the method asap, calling perfomSelector:onMainThread to do the init steps of the view controller to be pushed
  • Or even better, push the view controller asap, and do its init process in the viewDidLoad or viewWillAppear methods of this controller (you can add the activity controller in this new view).

If you pick the 1st option, you should call the deselectRowAtIndexPath method after you've pushed the new view controller and call stopAnimating on the indicator view from this deselectRowAtIndexPath method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文