iphone:如何在应用程序加载的某个时间预加载数据,就在 awakeFromNib 方法之后
在我的(非常简单)应用程序中,
-->我在启动时在主视图中加载了一个子视图(名为“Splash”),如下所示(在我的 mainView 类中):
-(void)awakeFromNib{
[self addSubview:splash];
}
-->我还有一个 UITableView(名为“myTable”),通过单击子视图“splash”中的按钮(调用名为“LoadData:”的 IBAction)来加载。 (所有视图都是在interfaceBuilder中创建的,每个视图在xCode项目中都有其相应的类)
我想要做的是在加载第二个子视图之前从SQLite数据库中预加载(缓存)大量数据(750个条目) (“myTable”),它使用存储在数组中的数据。
为了执行此操作,我有一个名为“RefreshData:”的方法,该方法在某个时间被调用以将结果存储在数组中。 该数组在 UITableView 中用于显示该数据。 一切都运行得很好,但是...
- 如果我在“mainView”类中的“awakeFromNib”方法末尾调用“RefreshData”方法,我的应用程序需要大约 15 秒才能显示第一个屏幕(名为“splash”) : 不好。
- 如果我在 IBAction“LoadData”中调用“RefreshData”,UITableView 需要大约 13 秒才能出现在屏幕上:一点也不好。
所以,问题是: 有没有办法在第一个子视图(“splash”)出现在屏幕上之后,并且在用户单击加载 UITableView 的按钮之前调用“RefreshData”方法?
任何帮助将不胜感激,请为我糟糕的英语道歉!
in my (quite simple) application,
--> i have one subview (named "Splash") loaded in the main view at launch time, like this (in my mainView class) :
-(void)awakeFromNib{
[self addSubview:splash];
}
--> I have also a UITableView (named "myTable") loaded by clicking a button (which calls the IBAction named "LoadData:") in the subview "splash".
(all views are made in interfaceBuilder, and each views have their corresponding classes in the xCode project)
What i want to do is to preload (cache) large amount of data (750 entries) from a SQLite database, before i load the second subView ("myTable"), which is using this data stored in an array.
To perform this, i have a method called "RefreshData:", which is called at a certain time to store the results in an array.
This array is used in the UITableView to show this data.
All is running perfectly well, but...
- if i call "RefreshData" method at the end of the "awakeFromNib" method in the "mainView" class, my app takes ~15 seconds to show the first screen (named "splash") : not good.
- if i call "RefreshData" within the IBAction "LoadData", the UITableView takes ~13 seconds to appear on screen : not good at all.
So, the question is :
is there a way to call the "RefreshData" method AFTER the first subView ("splash") did appear on screen, and BEFORE user clicks on the button which loads the UITableView ?
Any help will be appreciated, and please apologizes for my bad english !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
稍后尝试调用refreshData,即在
另外,如果SQL请求锁定了GUI,您也许应该考虑在新线程中提取数据(尽管我认为SQL做到了这一点)
Try calling refreshData a little later ie in
Also if the SQL request is locking up the GUI you should perhaps think about pulling the data off in a new thread (although I thought SQL did this)