iPhone 上不显示活动指示器

发布于 2024-09-16 08:30:53 字数 1264 浏览 3 评论 0原文

我在 iPhone 上使用标准导航器界面。当我从最高级别的表视图移动到下一个级别时,我必须从核心数据加载大约 2000 条记录,这可能需要 5-10 秒,所以我想使用活动指示器。

我已经完成了以下代码,如果删除 DidSelect 方法中的代码,该代码就可以工作,但否则指示器永远不会出现,即使在加载其他视图时视图仍然在那里等待。以下是方法:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{   
[tableView deselectRowAtIndexPath:indexPath animated:YES];

//-- start activity indicator (will be stopped when view disappears)
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
[cell.contentView addSubview:m_activityIndicator];
[m_activityIndicator startAnimating];


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



//--show the listViewController
CardListViewController *listViewController = [[CardListViewController alloc] initWithNibName:@"CardListViewController" bundle:nil];
NSString* selectedCardTypeName = [rootSelectionList objectAtIndex:indexPath.row];
enum CardTypes selectedCardType = cardTypeIDFromCardTypeName(selectedCardTypeName);
listViewController.selectedCardType =selectedCardType;
[self.navigationController pushViewController:listViewController animated:YES];
[listViewController release];


}

如何强制活动指示器在开始处理下一个列表视图控制器之前显示?

I am using a standard navigator interface on the iPhone. When I move from the highest level tableview to the next level, I have to load about 2000 records from core data, which can take 5-10 seconds, so I want to use an activity indicator.

I have done the following code which works if I remove the code in the DidSelect method, but otherwise the indicator never appears, even though the view still waits there while the other view loads. Here are the methods:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{   
[tableView deselectRowAtIndexPath:indexPath animated:YES];

//-- start activity indicator (will be stopped when view disappears)
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
[cell.contentView addSubview:m_activityIndicator];
[m_activityIndicator startAnimating];


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



//--show the listViewController
CardListViewController *listViewController = [[CardListViewController alloc] initWithNibName:@"CardListViewController" bundle:nil];
NSString* selectedCardTypeName = [rootSelectionList objectAtIndex:indexPath.row];
enum CardTypes selectedCardType = cardTypeIDFromCardTypeName(selectedCardTypeName);
listViewController.selectedCardType =selectedCardType;
[self.navigationController pushViewController:listViewController animated:YES];
[listViewController release];


}

How can I force the activity indicator to show up before it starts processing the the next listviewcontroller?

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

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

发布评论

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

评论(1

旧话新听 2024-09-23 08:30:53

首先,为什么需要同时加载2k行呢?你为什么不偷懒做呢?

首先,在加载表视图时,您将使用数据源仅计算要显示的行数,查询核心数据以仅获取行数,因此您的表视图将准备好显示所有必要的单元格。

其次,从核心数据中仅加载您需要的内容,这意味着仅加载屏幕上的内容。想象一下,如果用户非常快地拖动和滚动表格视图,许多单元格将在不需要它的情况下被加载。正确的做法是仅加载可见单元格,这意味着滚动过程停止时可见的单元格。

看一下 Apple 的这个示例,了解如何延迟加载表视图的资源: http://developer.apple.com/iphone/library/samplecode/LazyTableImages/Listings/Classes_RootViewController_m.html#//apple_ref/doc/uid/ DTS40009394-Classes_RootViewController_m-DontLinkElementID_12

它用于图像,但您可以对获取对象执行相同的操作。

懒惰地执行此操作,您将不需要活动指示器。

顺便说一句,回到活动指示器的问题,您可能需要要求您的手机进行更新:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{   
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    //-- start activity indicator (will be stopped when view disappears)
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell.contentView addSubview:m_activityIndicator];
    [m_activityIndicator startAnimating];
    [cell setNeedsDisplay];

    return indexPath;
}

干杯

First of all, why do you need to load the 2k rows at the same time? Why don't you do it lazily?

First, when loading the table view, you would use your datasource to only count the number of rows that you would display, querying the core data to get only the number, and so your table view would be ready to show all the necessary cells.

Second, load from core data only the content that you would need, it means, only the content on screen. Imagine if the user drag and scroll the table view very fast, many cell would be loaded without the need for it. The right thing to do is loading only the visible cells and it means the ones that would be visible when the scrolling process stops.

Have a look at this example from Apple on how to load resources for table view lazily: http://developer.apple.com/iphone/library/samplecode/LazyTableImages/Listings/Classes_RootViewController_m.html#//apple_ref/doc/uid/DTS40009394-Classes_RootViewController_m-DontLinkElementID_12

It's for images, but you can do the same idea for the fetching of objects.

Doing this lazily you wouldn't need the activity indicator.

BTW, going back to the issue with the activity indicator, you may need to ask you cell to update:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{   
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    //-- start activity indicator (will be stopped when view disappears)
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell.contentView addSubview:m_activityIndicator];
    [m_activityIndicator startAnimating];
    [cell setNeedsDisplay];

    return indexPath;
}

Cheers

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