iphone - iOS : How to Preload Data before Display

标签 iphone objective-c asynchronous preload appdelegate

在我正在制作的 iPhone 应用程序中,我有一个 initialViewController

(1) 带按钮。单击按钮后,它将转到另一个 View Controller

(2),此时从 CoreData 文件加载数据并将其显示给用户。

我的问题是(2)的加载和数据的实际显示之间有一个小的延迟。这当然是因为数据加载需要一点时间。我异步执行,我的目标是永远不显示旋转轮或加载屏幕(更用户友好)。

我想要做的是在(1)而不是(2)处“预加载”数据,这样数据应该在(2)加载时已经加载并且应该立即显示。 我知道如何在 (1) 处加载数据,但我不知道如何轻松地将其传递到 (2)。我无法使用 segue 来完成此操作,因为我的应用程序实际上比上面的描述要复杂一些,并且通过 segue 来完成此操作很麻烦。

我听说可以使用“AppDelegate”,但由于我是编程新手,我不知道如何有效地使用它。我一直关注的在线类(class)并没有给出关于如何使用它的非常清晰的见解,所以我有点迷失。

最佳答案

看到您对 Paras 帖子的评论后,我为您提供了更好的解决方案:

创建名为 fileLoader 的 NSObject 子类

//in fileLoader.h
@interface fileLoader : NSObject {
}
+(fileLoader *)sharedInstance;
+(void)createSharedInstance;
//add functions and variables to load, store data for use in another class
@end

那么,

//in fileLoader.m
@implementation fileLoader
static id _instance;


+(void)createSharedInstance{
    _instance = [[fileManager alloc] init];
}
+(fileManager *)sharedInstance{
    return _instance;
}
//other functions for storing, retrieving, loading, standard init function, etc.

@结束 现在,您可以调用 [fileManager createSharedInstance] 来实例化一个文件管理器,您可以通过调用 [fileManager sharedInstance] 上的函数从任何地方使用该文件管理器。

关于iphone - iOS : How to Preload Data before Display,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13307706/

相关文章:

iphone - 为 iPhone 应用程序生成类图

iphone - 如何以编程方式使用 UIScrollView 强制滚动?

iphone - UINavigationBar 弹出和弹出而不是滑动

ios - 选择器没有已知的类方法 'name'

ios - iOS,如何为有趣的应用程序划粗线?

iphone - NSDateFormatter 内存泄漏

c# - DataAdapter 填充异步异常

iphone - 如何设置用于 NSDictionary 的键值对?

c# - 将 Backgroundworker 重构为异步/等待

c# - 如何异步删除文件夹