Objective c plist输出值的问题
这是我第一次使用plist为我的应用程序存储一些数据。我现在的问题是我的应用程序给出了一个Objective c plist输出值的问题,objective-c,ios4,plist,Objective C,Ios4,Plist,这是我第一次使用plist为我的应用程序存储一些数据。我现在的问题是我的应用程序给出了一个EXC\u BAD\u访问错误。在我阅读plist的方法中,它给了我摘要不可用。但是NSMutableDictionary给了我2个key/paired,我的plist只有2个值,只是为了学习如何使用plist(目前)。我有一种感觉,由于这个摘要不可用,我得到了EXC\u BAD\u ACCESS`错误 -(void)readFile{ NSError *error; NSArray *pa
EXC\u BAD\u访问
错误。在我阅读plist的方法中,它给了我摘要不可用
。但是NSMutableDictionary给了我2个key/paired,我的plist只有2个值,只是为了学习如何使用plist(目前)。我有一种感觉,由于这个摘要不可用,我得到了
EXC\u BAD\u ACCESS`错误
-(void)readFile{
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
NSString *documentsDirectory = [paths objectAtIndex:0]; //2
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"EventAddress.plist"]; //3
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path]) //4
{
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"EventAddress" ofType:@"plist"]; // 5
[fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
}
NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile: path];
//load from savedStock both addr and event are NSString
addr = [savedStock objectForKey:@"Address"];
event = [savedStock objectForKey:@"Event"];
[savedStock release];
}
任何帮助都将不胜感激
更新1
Where the error occurred was at the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
...
...
// EXC_BAD_ACCESS happened at this line
[[cell textLabel] setText:addr];
}
但当@Jeff告诉我保留地址和事件时,事情就解决了。现在,我的新EXC\u BAD\u ACCESS
来自主.m文件:
int-retVal=UIApplicationMain(argc、argv、nil、nil)代码>
现在可能出了什么问题
更新2
这是我学会如何使用plist的网站。
在此之后是否使用addr
和event
的值?它们不会被保留,因此当savedStock
被删除时,它们也会被保留。如果这些是实例变量,请在将它们从字典中取出时保留它们。哪一行获得了EXC\u BAD\u访问权限?抱歉,没有正确编写问题。假设addr和event都显示在UITableViewCell
[[cell textlab]setText:addr]中代码>我将尝试@Jeff的回复,然后更新此问题。谢谢你的快速回复!