简体   繁体   English

NSArray列出到TableView

[英]NSArray to plist to TableView

Thanks in advance. 提前致谢。 I create an array with 6 parts, each an NSString in one of my views. 我创建了一个包含6个部分的数组,每个视图中有一个NSString。 Each string is taken from a UITextField. 每个字符串均取自​​UITextField。 I want to make a save button that saves the Array into a plist. 我要创建一个保存按钮,将数组保存到plist中。 I then want a TableView to display a table sorted by the first object in the array, the first string. 然后,我希望TableView显示一个按数组中第一个对象(第一个字符串)排序的表。

I've created a blank plist with the name I want and named the plist the same thing as the array. 我用所需名称创建了一个空白plist,并将该plist命名为与数组相同的名称。 Frankly, I'm lost after that. 坦白说,那之后我迷路了。 I don't understand if what I'm making is a dictionary in the plist or an array, and how to do it. 我不知道我要写的是plist还是数组中的字典,以及该怎么做。

Once the table is made, I think I can handle pushing new views from the selected row. 制作完表格后,我认为我可以处理从所选行中推送新视图的问题。

Anything would help. 一切都会有帮助的。 Thanks and stack overflow has been really helpful. 谢谢,堆栈溢出真的很有帮助。

Thanks again. 再次感谢。

If you are really set on using files, to this to write an array to your .plist: 如果您真的想使用文件,则可以将一个数组写入.plist:

NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
[dictionary setObject:theArray forKey:yourKey];
[dictionary writeToFile:@"/somepath/blah.plist" atomically:YES];
[dictionary release];

This will set the root of your .plist file to be a NSDictionary. 这会将.plist文件的根目录设置为NSDictionary。 If you want it to be an NSMutableArray just change the class of the *dictionary. 如果希望它成为NSMutableArray,则只需更改* dictionary的类。

Answer via: primary source 通过以下方式回答: 主要来源

To store data it's better to use NSUserDefaults and not files because reading and writing it it's much easier. 要存储数据,最好使用NSUserDefaults而不是文件,因为读取和写入数据要容易得多。 There is a primer at: Primer link 在这里有一个入门: 入门链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM