UIVIew 的持久存储

发布于 2024-12-06 14:47:27 字数 188 浏览 6 评论 0原文

我正在我的应用程序中动态创建一些“n”个 UIView 对象。我可以将这些对象拖放到屏幕中的任何位置& chenge 改变了他们的一些属性。现在我想用持久性存储来保存所有这些细节,这样每当我启动应用程序时,我就可以看到那些已经创建的对象。

那么最好的解决方案是什么?

另外,他们是否有适用于此表格的示例应用程序可供我参考?

I am creating dynamically some "n" number of UIView Object in my application.I can able to drag, drop these objects to any position in the screen & chenge change their some of property .Now i want to save all these details with persistance storage ,so that whenever i launched the application nest time, i can able to see those already created object.

So what is the best solution for this?

Also is their any sample application available for this form which i can take reference?

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

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

发布评论

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

评论(1

凌乱心跳 2024-12-13 14:47:27

我想你可以这样做。

// Create an array to store the properties
NSMutableArray *viewProperties = [NSMutableArray array]; 

// Loop through all the views
for (UIView *view in views) {

    // Create a dictionary for each view
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];

    // Store the properties in the dictionary
    [dict setValue:NSStringFromCGRect(view.frame) forKey:@"ViewFrame"];
    ...

    // Add the dictionary to the array
    [viewProperties addObject:dict];
}

// Finally add the array to persistence
[userDefaults setValue:viewProperties forKey:@"ViewProperties"];

稍后您可以从持久性中获取数组并使用属性创建视图。

NSMutableArray *viewProperties = [userDefaults valueForKey:@"ViewProperties"]; 

for (NSDictionary *dict in viewProperties) {

    UIView *view = [[UIView alloc] init];
    NSString *frameAsString = [dict valueForKey:@"ViewFrame"];
    view.frame = CGRectFromString(frameAsString);
    // Get other properties from dictionary and set it to view
}

I think you can do it this way.

// Create an array to store the properties
NSMutableArray *viewProperties = [NSMutableArray array]; 

// Loop through all the views
for (UIView *view in views) {

    // Create a dictionary for each view
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];

    // Store the properties in the dictionary
    [dict setValue:NSStringFromCGRect(view.frame) forKey:@"ViewFrame"];
    ...

    // Add the dictionary to the array
    [viewProperties addObject:dict];
}

// Finally add the array to persistence
[userDefaults setValue:viewProperties forKey:@"ViewProperties"];

Later you can get the array from persistence and create the views with the properties.

NSMutableArray *viewProperties = [userDefaults valueForKey:@"ViewProperties"]; 

for (NSDictionary *dict in viewProperties) {

    UIView *view = [[UIView alloc] init];
    NSString *frameAsString = [dict valueForKey:@"ViewFrame"];
    view.frame = CGRectFromString(frameAsString);
    // Get other properties from dictionary and set it to view
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文