3

我只是想将此数组保存为用户默认值,它会随机崩溃。有时它有效,有时它给我 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;
}
4

1 回答 1

1

这个技巧将允许您在异常上中断代码并让您直接检查为什么会发生这种情况: https ://stackoverflow.com/a/616526/46970

于 2012-09-07T12:38:02.750 回答