推送下一个视图时的活动指示符 - didSelectRowAtIndexPath [英] Activity Indicators when pushing next view - didSelectRowAtIndexPath

查看:125
本文介绍了推送下一个视图时的活动指示符 - didSelectRowAtIndexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以成功推送iPhone应用中的下一个视图。但是,导致下一个视图检索数据以填充 UITableViews ,有时等待时间可能是几秒或稍长,具体取决于连接。

I can successfully push only next view in my iPhone app. However, cause the next view retrieves data to populate the UITableViews, sometimes waiting time could be a few seconds or slightly longer depending on connection.

在此期间,用户可能认为该应用程序已冻结等等。因此,为了解决这个问题,我认为实施 UIActivityIndi​​cators 将是一个很好的方法。让用户知道应用程序正在运行。

During this time, the user may think the app has frozen etc. So, to counter this problem, I think implementing UIActivityIndicators would be a good way to let the user know that the app is working.

有人可以告诉我在哪里可以实现这个吗?

Can someone tell me where I could implement this?

谢谢。

pushDetailView方法

- (void)pushDetailView {

[tableView deselectRowAtIndexPath:indexPath animated:YES];
//load the clicked cell.
DetailsImageCell *cell = (DetailsImageCell *)[tableView cellForRowAtIndexPath:indexPath];

//init the controller.
AlertsDetailsView *controller = nil;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
    controller = [[AlertsDetailsView alloc] initWithNibName:@"DetailsView_iPad" bundle:nil];
} else {
    controller = [[AlertsDetailsView alloc] initWithNibName:@"DetailsView" bundle:nil];
}

//set the ID and call JSON in the controller.
[controller setID:[cell getID]];

//show the view.
[self.navigationController pushViewController:controller animated:YES];


推荐答案

您可以在中实现此功能didSelectRowAtIndexPath:方法本身。

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge];
cell.accessoryView = spinner;
[spinner startAnimating];
[spinner release];

这将显示单元格右侧的活动指示器,这将使用户感觉到某些东西正在加载。

This will show the activity indicator at the right side of the cell which will make the user feel that something is loading.

编辑如果您设置 accessoryView 并以相同的方法编写加载代码,只有在所有操作完成后,UI才会更新。解决此问题的方法是在 didSelectRowAtIndexPath:方法中设置 activityIndi​​cator 并调用视图控制器推送代码有一些延迟。

If you set the accessoryView and write the loading code in the same method, the UI will get updated only when all the operations over. A workaround for this is to just set the activityIndicator in the didSelectRowAtIndexPath: method and call the view controller pushing code with some delay.

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

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge];
    cell.accessoryView = spinner;
    [spinner startAnimating];
    [spinner release];

    [self performSelector:@selector(pushDetailView:) withObject:tableView afterDelay:0.1];
}

- (void)pushDetailView:(UITableView *)tableView {

    // Push the detail view here
}

这篇关于推送下一个视图时的活动指示符 - didSelectRowAtIndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆