在加载大表时向用户发送消息
我正在处理几个大型 RSS 源并在 TableView 中显示结果。用户单击相关选项卡后开始处理。一切运行良好,但由于处理需要几秒钟的时间,因此在处理完成之前,NIB 和表不会加载,并且看起来 iPhone 已经卡住了。我已向 NIB 添加了一个活动指示器,但由于它在表格准备好显示之前不会加载,因此看起来太晚了,没有任何用处。
有谁知道如何在表构建/加载时向用户显示消息?我尝试先加载 UIView 并将表添加为子视图,但同样,两者似乎仅在表准备好后才加载。
指导表示赞赏。
I am processing several large RSS feeds and displaying results in a TableView. The processing starts after the user clicks on the relevant tab. All works well, but as it takes a couple of seconds to process, the NIB and Table don't load until the processing finishes and it looks like the iPhone has seized up. I have added an Activity indicator to the NIB, but because it doesn't load until the table is ready to display, it appears too late to be of any use.
Does anyone have any ideas how to display a message to a user while the table builds/loads? I have tried loading a UIView first and adding the Table as a subview but, again, both seem to load only after the table is ready.
Guidance appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从您的描述中很难猜测发生了什么,但看起来您的调用不是异步的。以下是您应该在代码中执行的操作:
使所有调用异步。你说你的手机坏了。听起来就像您的请求和响应发生在主线程上。有许多库可以用来处理异步调用。 ASIHTTPRequest 为例......
不要等待数据进来显示tableView。设计原则是加载尽可能多的 UI,以便用户在后台加载数据时可以看到一些内容。您应该做的是初始化 NSMutableArray 来保存数据。最初该数组不包含任何对象。这是您在数据源方法中使用的数组:对
numberOfRowsInSection
使用数组大小,并在cellForRowAtIndexPath
中使用数组对象。一旦您的 RSS feed XML 进入并被解析,将其存储在您的数组中并调用[tableView reloadData]
。这样您就不会让用户看到空白屏幕。 (另一个好的做法是,当数组大小为零时,在 tableview 中显示一个单元格,表示“数据正在加载”或其他内容)。当您首次初始化并加载表格,然后触发这些 RSS 提要请求时,您将在 tableView 上显示活动指示器视图。当 RSS 数据进入且 tableView 重新加载时,停止为指示器设置动画。
这些是在表格视图中显示非本地数据时应遵循的标准步骤。带来流畅的用户体验。
就像我之前说过的,从你的问题看来,你的调用不是异步的。如果我错了,请纠正我,让我们从那里开始......
It's kind of hard to guess what's going on from your description but it looks like your calls aren't asynchronous. Here's what you should be doing in your code:
Make all calls asynchronous. You said your phone is seizing up. Makes it sound like your requests and responses are happening on the main thread. There are many libraries you could use to handle asynchronous calls. ASIHTTPRequest for one example....
Don't wait for the data to come in before displaying the tableView. It's a design principle that you load as much of the UI as possible so that the user has something to look at while your data loads up in the background. What you should be doing is initializing an NSMutableArray to hold the data. Initially this array will contain no objects. This is the array that you use in your data source methods: Use array size for
numberOfRowsInSection
and use the array objects incellForRowAtIndexPath
. Once your RSS feed XML comes in and is parsed, store that in your arrays and call[tableView reloadData]
. This way you don't leave your users looking at a blank screen. (Another good practice is when the array size is zero, show one cell in your tableview that says "data is loading" or something).When you first initialize and load up your table and then fire off those RSS feed requests, that's where you show an activity indicator view on the tableView. Stop animating the indicator when the RSS data comes in and your tableView reloads.
These are the standard steps you should follow while showing non local data in a tableview. Makes for a smooth user experience.
Like I said before, it seems from your question that your calls are not asynchronous. If I'm wrong, correct me and let's take it from there...