K.H*_*nda 3 iphone spinner uitableview uiview uiactivityindicatorview
我可以在我的iPhone应用程序中成功推送下一个视图.但是,导致下一个视图检索数据以填充UITableViews,有时等待时间可能是几秒或稍长,具体取决于连接.
在此期间,用户可能认为应用程序已冻结等.因此,为了解决这个问题,我认为实施UIActivityIndicators将是让用户知道应用程序正在运行的好方法.
有人能告诉我在哪里可以实现这个吗?
谢谢.
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];
Run Code Online (Sandbox Code Playgroud)
您可以在didSelectRowAtIndexPath:方法本身中实现此功能.
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge];
cell.accessoryView = spinner;
[spinner startAnimating];
[spinner release];
Run Code Online (Sandbox Code Playgroud)
这将显示单元格右侧的活动指示器,这将使用户感觉有东西正在加载.
编辑:如果您设置accessoryView并以相同的方法编写加载代码,UI将仅在所有操作结束时更新.解决方法是在didSelectRowAtIndexPath:方法中设置activityIndicator并调用视图控制器推送代码有一些延迟.
- (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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2132 次 |
| 最近记录: |