iOS中如何管理数据库

发布于 2024-10-22 19:56:58 字数 156 浏览 0 评论 0原文

我必须制作一个 iPhone 应用程序。 我有一个按钮,按钮名称是 xib 中的注册,如果我单击该按钮,则注册表单将打开,

注册表单是在网络服务器中创建的 如果用户填写注册表 假设他在注册时填写了用户名和密码,它将保存在服务器中,并且相同的用户名和密码也应该保存在本地数据库中。

I have to make an iPhone application.
I have one button and button name is registration in xib if I click the button then registration form will be open

the registration form is created in web server
if the user fill the registration form
suppose he fill the username and password in registration it will save in server and same username and password should save in or local database also.

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

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

发布评论

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

评论(1

鹤舞 2024-10-29 19:56:58

您有 3 个主要选项来保存登录数据;设置、核心数据和 SqlLite。对于仅用户名和密码,您只需要使用“设置”,因为其他两个选项的开销会太大,并且它们更常用于关系数据。

要使用设置,您需要在应用程序控制器初始化时通过调用加载它们;

+ (void) loadDefaultSettings {

    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSString *pListPath = [path stringByAppendingPathComponent:@"Settings.bundle/Root.plist"];
    NSDictionary *pList = [NSDictionary dictionaryWithContentsOfFile:pListPath];

    NSMutableArray *prefsArray = [pList objectForKey:@"PreferenceSpecifiers"];
    NSMutableDictionary *regDictionary = [NSMutableDictionary dictionary];

    for (NSDictionary *dict in prefsArray) {
        NSString *key = [dict objectForKey:@"Key"];
        if (key) {
            id value = [dict objectForKey:@"DefaultValue"];
            [regDictionary setObject:value forKey:key];
        }
    }

    [[NSUserDefaults standardUserDefaults] registerDefaults:regDictionary];
}

然后,您可以通过对此的方法调用来存储您的用户名和密码;

+ (void) storePersistedLogin:(NSString *)uid withPassword:(NSString *)pswd  {
    [[NSUserDefaults standardUserDefaults] setObject:uid forKey:@"UID"];
    [[NSUserDefaults standardUserDefaults] setObject:pswd forKey:@"PSWD"];
}

您可以使用以下方法填充 UITextField 输入;

+ (void) populatePersistedLogin:(UITextField **)uid andPassword:(UITextField **)pswd {
    [*uid setText:(NSString *)[[NSUserDefaults standardUserDefaults] objectForKey:@"UID"]];
    [*pswd setText:(NSString *)[[NSUserDefaults standardUserDefaults] objectForKey:@"PSWD"]];
}

我在单独的 SettingsUtils 类中拥有这些公共方法,因此我可以确保我的密钥是相同的。您还可以将键声明为 NSString 对象,以减少输入错误的可能性。

You have 3 main options for persisting the login data; Settings, Core Data and SqlLite. For just a username and password you only need to use the Settings as the overhead of the other two options would be excessive and they are more often used for relational data.

To use Settings you need to load them when the application controller initialises by calling;

+ (void) loadDefaultSettings {

    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSString *pListPath = [path stringByAppendingPathComponent:@"Settings.bundle/Root.plist"];
    NSDictionary *pList = [NSDictionary dictionaryWithContentsOfFile:pListPath];

    NSMutableArray *prefsArray = [pList objectForKey:@"PreferenceSpecifiers"];
    NSMutableDictionary *regDictionary = [NSMutableDictionary dictionary];

    for (NSDictionary *dict in prefsArray) {
        NSString *key = [dict objectForKey:@"Key"];
        if (key) {
            id value = [dict objectForKey:@"DefaultValue"];
            [regDictionary setObject:value forKey:key];
        }
    }

    [[NSUserDefaults standardUserDefaults] registerDefaults:regDictionary];
}

You can then store your username and password with a method call to this;

+ (void) storePersistedLogin:(NSString *)uid withPassword:(NSString *)pswd  {
    [[NSUserDefaults standardUserDefaults] setObject:uid forKey:@"UID"];
    [[NSUserDefaults standardUserDefaults] setObject:pswd forKey:@"PSWD"];
}

You can populate the UITextField inputs using the following method;

+ (void) populatePersistedLogin:(UITextField **)uid andPassword:(UITextField **)pswd {
    [*uid setText:(NSString *)[[NSUserDefaults standardUserDefaults] objectForKey:@"UID"]];
    [*pswd setText:(NSString *)[[NSUserDefaults standardUserDefaults] objectForKey:@"PSWD"]];
}

I have these public methods in a separate SettingsUtils class so I can make sure my keys are the same. You could also declare the keys as NSString objects instead to reduce the chance of mis-typing them.

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