创建NSDictionary的NSMutalbeArray时为E

创建NSDictionary的NSMutalbeArray时为E

我正在尝试填充字典数组。但是xcode说EXC_BAD_ACCESS

这是基本操作。错误在哪里?

@interface MenuViewController ()
@property (nonatomic, strong) NSMutableArray *items;
@end

@implementation MenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.items = [[NSMutableArray alloc]initWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"home",@"title","MenuHomeIcon.png",@"image", nil],
                                                        [NSDictionary dictionaryWithObjectsAndKeys:@"home",@"title","MenuFindIcon.png",@"image", nil],
                                                        [NSDictionary dictionaryWithObjectsAndKeys:@"home",@"title","MenuProfileIcon.png",@"image", nil],
                                                        [NSDictionary dictionaryWithObjectsAndKeys:@"home",@"title","MenuSettingsIcon.png",@"image", nil],nil];

}


我尝试了另一种方法,但结果是相同的:

- (void)viewDidLoad {
    [super viewDidLoad];

    self.items = [[NSMutableArray alloc]initWithCapacity:4];

    [self.items addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"home",@"title","MenuHomeIcon.png",@"image", nil]];
    [self.items addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"home",@"title","MenuFindIcon.png",@"image", nil]];
    [self.items addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"home",@"title","MenuProfileIcon.png",@"image", nil]];
    [self.items addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"home",@"title","MenuSettingsIcon.png",@"image", nil]];

}

最佳答案

图像名称字符串之前缺少@

[self.items addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"home",@"title","MenuHomeIcon.png",@"image", nil]];


应该

[self.items addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"home",@"title",@"MenuHomeIcon.png",@"image", nil]];

关于ios - 创建NSDictionary的NSMutalbeArray时为EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30504289/

10-09 12:27