财产清单管理

发布于 2024-09-13 18:02:44 字数 1303 浏览 2 评论 0 原文

我正在尝试创建一个具有用户列表的应用程序,并且每个用户都将被分配一个可编辑的数据数组。我是持久数据的新手,所以我认为属性列表是最容易使用的。应用程序的第一个视图将有一个至少已编辑其姓名的用户列表,然后为每个尚未编辑任何内容的属性列表提供“新用户”。 (我确信有代码可以让程序在每次有人单击“新用户”时创建新的属性列表,但这对我来说可能太困难了,所以目前我只是简单地定义了 3 个属性列表,它们将对应与我的 3 个用户。)

因此,对于我的应用程序主屏幕的“viewDidLoad”部分,我需要使用 3 个用户的名称填充 UIPicker(如果没有任何编辑,则为“新用户”)。我这样做了:

NSString *filePathForProfile1 = [self dataForProfile1];
NSString *filePathForProfile2 = [self dataForProfile2];
NSString *filePathForProfile3 = [self dataForProfile3];


if ([[NSFileManager defaultManager] fileExistsAtPath:filePathForProfile1]) {

    NSArray *arrayProfile1 = [[NSArray alloc]initWithContentsOfFile:filePathForProfile1];
    NSArray *arrayProfile2 = [[NSArray alloc]initWithContentsOfFile:filePathForProfile2];
    NSArray *arrayProfile3 = [[NSArray alloc]initWithContentsOfFile:filePathForProfile3];

    NSArray *array = [[NSArray alloc]initWithObjects:[arrayProfile1 objectAtIndex:0],[arrayProfile2 objectAtIndex:0],[arrayProfile3 objectAtIndex:0],nil];



    self.profileData = array;
    arrayProfile1.release;
    arrayProfile2.release;
    arrayProfile3.release;
}

现在,因为我一直在运行该程序,所以已经为 Profile1 保存了一个文件,因此选择器确实显示了该文件的名称 - 但对于我来说,我无法完全弄清楚如何拥有它为其他 2 显示“新用户”。我尝试使用该 fileExistsAtPath 参数设置一个 if-then 语句,以使用“新用户”创建初始化数组,但随后我无法将数组从参数中传递出去。请帮助!

I am trying to create an app that has a list of users and each user will be assigned an array of data that is editable. I am new to persistent data so i thought a property list would be the easiest to use. The first view of the app will have a list of the users that have already edited at least their name, and then have "New User" for each property list that has not yet had anything edited. (I am sure there is code to have the program create new property lists each time a person clicked on "New User" but that is probably far too difficult for me so for the time being I have just simply defined 3 property lists that will correspond with my 3 users.)

So, for the 'viewDidLoad' portion of my apps main screen i need to populate a UIPicker with the names of the 3 users (or "New User" if there have not been any editing). I did this:

NSString *filePathForProfile1 = [self dataForProfile1];
NSString *filePathForProfile2 = [self dataForProfile2];
NSString *filePathForProfile3 = [self dataForProfile3];


if ([[NSFileManager defaultManager] fileExistsAtPath:filePathForProfile1]) {

    NSArray *arrayProfile1 = [[NSArray alloc]initWithContentsOfFile:filePathForProfile1];
    NSArray *arrayProfile2 = [[NSArray alloc]initWithContentsOfFile:filePathForProfile2];
    NSArray *arrayProfile3 = [[NSArray alloc]initWithContentsOfFile:filePathForProfile3];

    NSArray *array = [[NSArray alloc]initWithObjects:[arrayProfile1 objectAtIndex:0],[arrayProfile2 objectAtIndex:0],[arrayProfile3 objectAtIndex:0],nil];



    self.profileData = array;
    arrayProfile1.release;
    arrayProfile2.release;
    arrayProfile3.release;
}

Now, because I have been running the program, there is already a file saved for Profile1 so the picker does display the name for that one - but for the life of me I can't quite figure out how to have it display "New User" for the other 2. I tried to set up an if-then statement with that fileExistsAtPath argument to create init the array with "New User" but then I couldn't pass the array out of the argument. Help Please!!

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

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

发布评论

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

评论(1

油焖大侠 2024-09-20 18:02:44

我建议您查看 存档和序列化编程指南
对于您的问题,最合适的解决方案(还有核心数据......)可能是对象序列化。

您可能有一个“Person”对象数组,而 Person 类有一个“Data”对象的 MutableArray。
然后您所要做的就是使 Person-Class 和 Data-Classe(s) NSCoding 兼容。之后,您可以通过以下简单方法轻松保存人员数组: [NSKeyedArchiver archiveRootObject:yourPersonsArray toFile:yourFilePath];

还有一个有用的教程 NSCoding / NSkeyedArchiver 教程

欢呼者,

萨姆

I would recommend you to have a look at the Archives and Serializations Programming Guide.
The most proper solution (well there is core data as well...) for your problem could be object serialisation.

You probably have an array of "Person"-Objects and the Person Class has a MutableArray of "Data"-Objects.
All you have to do then is make the Person-Class and the Data-Classe(s) NSCoding compliant. Afterwards you can easily persist your Array of Persons by something as easy as : [NSKeyedArchiver archiveRootObject:yourPersonsArray toFile:yourFilePath];

also there is a usefull tutorial found NSCoding / NSkeyedArchiver Tutorial

cheeers,

sam

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