我正在使用数组字典。我想在plist中的索引0处保存两个值。我想保存用户点击按钮时动态显示在标签上的名称和城市名称,然后我想通过使用
在桌面视图中显示它我已经尝试了一些具有以下知识的代码:
-(IBAction) myBrand:(id) sender
{
NSMutableArray *array = [[NSMutableArray alloc] init];
// get paths from root direcory
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *docsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0]; // get the path to our Data/plist file
NSString *plistPath = [docsDir stringByAppendingPathComponent:@"Data.plist"];
//This copies objects of plist to array if there is one
[array addObjectsFromArray:[NSArray arrayWithContentsOfFile:plistPath]];
[array insertObject:entity atIndex:0];
[array insertObject:category atIndex:0];
NSDictionary *plistDict = [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects: entity, category, nil] forKeys:[NSArray arrayWithObjects: @"Entity", @"Category", nil]];
[plistDict writeToFile:plistPath atomically: TRUE];
}
所以朋友们,请帮我解决如何进一步的问题。
此致 兰吉特
答案 0 :(得分:0)
您可能希望使用CoreData来保存数据,并使用NSFetchedResultsController来显示它们。在这里完成整个过程是不合理的,因为教程是可用的,Xcode包含由NSFetchedResultsController支持的表的模板。以下是两个可以帮助您入门的教程:
http://cocoadevcentral.com/articles/000085.php
http://www.raywenderlich.com/999/core-data-tutorial-how-to-use-nsfetchedresultscontroller