小编Bod*_*dar的帖子

Objective-c问题通过循环遍历数组

我有这个代码,它接受来自Core Data的收入对象数组.

- (void)totalIncome:(NSMutableArray *)IncomesArray {
    int i;
    int total;
    for (i = 0; i < [IncomesArray count]; ++i)
    {
        Income *income = [IncomesArray objectAtIndex:i];

        total += (int)[income value];
        NSLog(@"%@", total);
    }
    self.totalIncomes = [[NSNumber alloc] initWithInt:(int)total];
    NSLog(@"%.2f", self.totalIncomes);
}
Run Code Online (Sandbox Code Playgroud)

但行NSLog(@"%@",总计); 导致EXEC BAD ACCESS错误.有没有明显的事我做错了.此外,如果我删除日志,则没有添加到totalIncomes中,在我的头文件中声明为NSNumber.谢谢.

int core-data objective-c nsarray ios

0
推荐指数
1
解决办法
1687
查看次数

标签 统计

core-data ×1

int ×1

ios ×1

nsarray ×1

objective-c ×1