检索阵列时本地存储崩溃

时间:2013-11-10 06:47:24

标签: ios iphone ios6 crash xcode5

我无法理解为什么我的应用程序崩溃了,我怎么能避免它,

in .h

  @property (nonatomic)  NSArray * PersonsFromSearch;

in .m

崩溃区

 viewDidLoad
NSArray* nameArr;
   if([defaults objectForKey:@"Person1"])
   {
       nameArr = [NSArray arrayWithObjects: [defaults objectForKey:@"Person1"],Nil];//ate
       PersonsFromSearch = nameArr;//crashes here  :(
       NSLog(@"not crashed yet");
   }

在同一文件分配到本地存储

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self dismissKeyboard];
    //test solution :)
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];//store it !
    [defaults setObject:[PersonsFromSearch objectAtIndex:indexPath.row]     forKey:@"Person1"];//store 1 person Full details
    [[NSUserDefaults standardUserDefaults] synchronize];//store indeed
    //keep with code
}

崩溃详情:

2013-11-10 08:50:47.938 RevealControllerProject [1375:a0b] - [__ NSCFArray objectForKey:]:无法识别的选择器发送到实例0xe008a00

2013-11-10 08:50:47.942 RevealControllerProject [1375:a0b] * 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [__ NSCFArray objectForKey:]:无法识别的选择器已发送例如0xe008a00'

* 第一次抛出调用堆栈:

1 个答案:

答案 0 :(得分:0)

使用PersonsFromSearch =[NSArray arrayWithArray:nameArr];