从 NSOperation 调用时 UITableView 会休眠
我正在编写一个应用程序,每当用户点击重新加载按钮时,它都需要从网站获取其内容。
如果他这样做,一个 NSOperation 就会被注册并放入 NSOperationQueue 中。
当 NSOperation 启动(START QUEUE)时,它会检查其缓存并从服务器重新加载数据(CALL IMPORT1)。
执行此任务后,操作将向我的 UITableView 发送一条通知,该通知查询数据库(开始读取/结束读取),然后调用 [self.tableView reloadData];
(RELOAD DATA START)
直到这里一切都按预期进行。即使我导入大约 1.000 个元素。
让我发疯的是,在“END QUEUE”和获取第一个单元格(CREATE CELL START)之间有某种睡眠。经过这次睡眠后,细胞就会按其应有的速度生成——速度非常快。
我不明白是什么引发了这种“睡眠”。
任何人都可以给我提示出了什么问题吗?
预先感谢 Boris
在 viewDidAppear 中调用
2011-01-29 15:54:34.460 [30488:207] 开始阅读 2011-01-29 15:54:34.461 [30488:207] 阅读结束
2011-01-29 15:54:34.464 [30488:207] 重新加载数据开始 2011-01-29 15:54:34.468 [30488:207] 获取部分 2011-01-29 15:54:34.469 [30488:207] 获取标题 2011-01-29 15:54:34.470 [30488:207] 获取标头 2011-01-29 15:54:34.470 [30488:207] 获取行
2011-01-29 15:54:34.471 [30488:207] 创建单元格开始 2011-01-29 15:54:34.473 [30488:207] 创建单元格 停止 2011-01-29 15:54:34.474 [30488:207] 创建单元格启动
2011-01-29 15:54:34.475 [30488:207] 创建单元停止 2011-01-29 15:54:34.476 [30488:207] 创建单元格 开始 2011-01-29 15:54:34.477 [30488:207] 创建单元格停止
2011-01-29 15:54:34.477 [30488:207] 获取标题
通过通知调用(粗体部分是新的,因为 NSOperation)
2011-01-29 15:54:04.719 [30488:630b] 启动队列 2011-01-29 15:54:05.727 [30488:630b] 调用导入 1 开始
2011-01-29 15:54:05.750 [30488:630b] 呼叫导入1停止2011-01-29 15:54:05.760 [30488:630b] 通话视图 开始 2011-01-29 15:54:05.767 [30488:630b] 开始阅读
2011-01-29 15:54:05.771 [30488:630b] 阅读结束 2011-01-29 15:54:05.781 [30488:630b] 重新加载数据开始
2011-01-29 15:54:05.786 [30488:630b] 获取部分 2011-01-29 15:54:05.791 [30488:630b] 获取标头 2011-01-29 15:54:05.797 [30488:630b] 获取标头
2011-01-29 15:54:05.802 [30488:630b] 获取行
2011-01-29 15:54:05.806 [30488:630b] 呼叫视图停止 2011-01-29 15:54:05.811 [30488:630b] 结束队列 2011-01-29 15:54:10.770 [30488:630b] 创建单元格开始 2011-01-29 15:54:10.776 [30488:630b] 创建单元格 停止 2011-01-29 15:54:10.777 [30488:630b] 创建单元格启动
2011-01-29 15:54:10.778 [30488:630b] 创建单元停止 2011-01-29 15:54:10.778 [30488:630b] 创建单元格 开始 2011-01-29 15:54:10.780 [30488:630b] 创建单元格停止
2011-01-29 15:54:10.781 [30488:630b] 获取标题
I´m writing an app which needs to get its content from a website whenever the user taps a reload button.
If he does so an NSOperation is registered and put to NSOperationQueue.
When the NSOperation is starting (START QUEUE) it checks its cache and reloads the data from the server (CALL IMPORT1).
After this task the operation sends an Notification to my UITableView which queries the database (START READING / END READING) and then calls [self.tableView reloadData];
(RELOAD DATA START)
Until here everything works as expected. Even if i import about 1.000 elements.
The thing that drives my crazy is that there´s some kind of sleep between "END QUEUE" and getting the first cell (CREATE CELL START). After this sleep the cells are created as they should be - very fast.
I can´t figure out what invokes this "sleep".
Can anybody please give me an hint what´s going wrong.
Thanks in advance Boris
Called within viewDidAppear
2011-01-29 15:54:34.460 [30488:207]
START READING 2011-01-29
15:54:34.461 [30488:207] END READING
2011-01-29 15:54:34.464 [30488:207]
RELOAD DATA START 2011-01-29
15:54:34.468 [30488:207] GET SECTIONS
2011-01-29 15:54:34.469 [30488:207]
GET HEADER 2011-01-29 15:54:34.470
[30488:207] GET HEADER 2011-01-29
15:54:34.470 [30488:207] GET ROWS
2011-01-29 15:54:34.471 [30488:207]
CREATE CELL START 2011-01-29
15:54:34.473 [30488:207] CREATE CELL
STOP 2011-01-29 15:54:34.474
[30488:207] CREATE CELL START
2011-01-29 15:54:34.475 [30488:207]
CREATE CELL STOP 2011-01-29
15:54:34.476 [30488:207] CREATE CELL
START 2011-01-29 15:54:34.477
[30488:207] CREATE CELL STOP
2011-01-29 15:54:34.477 [30488:207]
GET HEADER
Called via Notification (The bold parts are new because of the NSOperation)
2011-01-29 15:54:04.719 [30488:630b] START QUEUE 2011-01-29 15:54:05.727
[30488:630b] CALL IMPORT1 START
2011-01-29 15:54:05.750 [30488:630b]
CALL IMPORT1 STOP 2011-01-29
15:54:05.760 [30488:630b] CALL VIEW
START 2011-01-29 15:54:05.767
[30488:630b] START READING
2011-01-29 15:54:05.771 [30488:630b]
END READING 2011-01-29 15:54:05.781
[30488:630b] RELOAD DATA START
2011-01-29 15:54:05.786 [30488:630b]
GET SECTIONS 2011-01-29 15:54:05.791
[30488:630b] GET HEADER 2011-01-29
15:54:05.797 [30488:630b] GET HEADER
2011-01-29 15:54:05.802 [30488:630b]
GET ROWS
2011-01-29 15:54:05.806 [30488:630b] CALL VIEW STOP 2011-01-29
15:54:05.811 [30488:630b] END QUEUE
2011-01-29 15:54:10.770 [30488:630b]
CREATE CELL START 2011-01-29
15:54:10.776 [30488:630b] CREATE CELL
STOP 2011-01-29 15:54:10.777
[30488:630b] CREATE CELL START
2011-01-29 15:54:10.778 [30488:630b]
CREATE CELL STOP 2011-01-29
15:54:10.778 [30488:630b] CREATE CELL
START 2011-01-29 15:54:10.780
[30488:630b] CREATE CELL STOP
2011-01-29 15:54:10.781 [30488:630b]
GET HEADER
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到解决方案... NSOperation 在辅助线程上将 NSNotification 发送到我的 UITableViewController - 这会导致延迟。
我在这个网站上找到了解决方案:
http://cocoawithlove.com/2009/08/safe -threaded-design-and-inter-thread.html
希望这对某人有帮助!
Found the solution... the NSOperation sends the NSNotification on the secondary thread to my UITableViewController - this causes the delay.
I found the solution on this site:
http://cocoawithlove.com/2009/08/safe-threaded-design-and-inter-thread.html
Hope this my help somebody!