[英]Can't add NSMutableArray to NSMutableArray
This must be one of those errors, where you have been staring at the code, for so long, that you can't find the error. 这肯定是其中一个错误,你一直盯着代码,这么久,你找不到错误。
I have this code block, where i loop through a NSMutableArray, containing multiple NSMutableArrays: 我有这个代码块,我循环遍历NSMutableArray,包含多个NSMutableArrays:
// FoodViewController.m
#import "FoodViewController.h"
@interface FoodViewController ()
@property (strong,nonatomic) NSMutableArray *breakfast;
@end
@implementation FoodViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *meals = [[dbManagerClass getSharedInstance]findCurrentDay];
for (NSMutableArray *row in meals) {
[self.breakfast addObject:row];
}
NSLog(@"%@",self.breakfast);
}
@end
I can see that ii have something in my *meals, because i get the following from NSLog'ing it: 我可以看到ii在我的饭菜中有一些东西,因为我从NSLog获得以下内容:
(
(
2,
Dinner,
Pizza,
574,
"20.03.2014",
empty
),
(
3,
Breakfast,
"Buttered toast",
394,
"20.03.2014",
empty
)
But somehow it doesn't get added to the breakfast-NSMutableArray, as NSLog returns "null". 但不知怎的,它没有被添加到早餐-NSMutableArray中,因为NSLog返回“null”。
You dont initialize breakfast
array before adding. 在添加之前,你不要初始化
breakfast
阵列。
Do this 做这个
self.breakfast = [NSMutableArray array];
for (NSMutableArray *row in meals) {
[self.breakfast addObject:row];
}
NSLog(@"%@",self.breakfast);
如果你不需要循环那么:
self.breakfast = [NSMutableArray arrayWithArray:meals];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.