嗯,我想你有点想多了。我只会创建一个可以处理我的人的类,在这种情况下是你的“Person”类。
我会简单地使用 Core Data 存储每个人。然后,当需要显示它们时,我只需发出一个获取请求并将所有人员管理的对象存储到 NSMutableArray(它只处理对象数组)中。然后,您可以简单地使用索引值在 tableView 中显示数组中的众多人员。
总的来说,我会:
1. For every person, create instance of Person.
2. Verify if person exists in my Core Data Person Entity.
3. If not, then insert into Core Data (the object will become an
NSManagedObject).
4. For displaying, simply do a fetch request to pull all persons in your
entity. Here I prefer to store the
results into an NSMutableArray, but
that is completely up to you. Make
sure you release your fetch request
after the results are store in the
array.
5. Reference them to your table view using the index value for each
person NSManagedObject in the array.
对于不涉及简单存储的东西:
1. Create instance of Person for every entry.
2. Add Person object to array.
3. Reference each Person to table view using index value.
最终,您所采取的方法将取决于您要如何处理这些信息。
至于阅读 plist,我会选择阅读一个 XML,你只需要一个 XML Parser 类(解析器有几个选项)。因为除了解析 XML 之外我什么都不做,所以我使用 NSXMLParser,但这个选择也取决于你。只需创建一个 NSXMLParser 类(确保解析器找到给定元素时的不同操作在该解析器中起作用)。所以是的,你需要添加到 NSXMLParser 来处理每个元素。这真的比听起来容易。
此外,通过存储在 Core Data 中,您始终可以在不使用 Singleton 的情况下获取信息。