保存用户默认值时随机BAD ACCESS

时间:2012-09-07 12:19:18

标签: iphone objective-c ios arrays

我只是想将此数组保存到用户默认值,它会随机崩溃。有时它有效,有时它给我EXC_BAD_ACCESS。我没有正确地发布一些东西吗?

- (void)setTextValue:(NSString *)valueText indexToSet:(NSUInteger)index
{
    [self.pageData replaceObjectAtIndex:index withObject:valueText];
    [[NSUserDefaults standardUserDefaults] setObject:self.pageData forKey:@"mynotes"];
}

这是我确定导致错误的方法。这是Xcode已经创建的一种方法,我将自己的自定义代码添加到。

- (nbookDataViewController *)viewControllerAtIndex:(NSUInteger)index storyboard:(UIStoryboard *)storyboard
{   
    nbookDataViewController *dataViewController = [storyboard instantiateViewControllerWithIdentifier:@"nbookDataViewController"];
    if (self.pageData.count > 0 && index < self.pageData.count)
    {
        NSString *val = (NSString *)[self.pageData objectAtIndex:index];
        dataViewController.dataObject = val;
    }
    else
    {
        NSDate *date = [NSDate date];
        NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
        [dateFormat setDateFormat:@"MMMM d, YYYY"];
        NSString *dateString = [dateFormat stringFromDate:date];
        //[dateFormat release];
        [self.pageData addObject:dateString];
        dataViewController.dataObject = (NSString *)[self.pageData objectAtIndex:index];
    }
    dataViewController.myModel = (nbookModelController *)self;
    dataViewController.dIndex = index;
    //[self.mySaveData setObject:self.pageData forKey:@"mynotes"];
    return dataViewController;
}

1 个答案:

答案 0 :(得分:1)

这个提示将允许您编写代码以打破异常并让您直接检查为什么会发生这种情况: https://stackoverflow.com/a/616526/46970