我正在尝试根据NSDictionary
内部的位置将数组中的对象添加到NSArray
,但是只要NSDictionary
被分配,应用就会崩溃。有什么想法吗?
NSString *venue_title = [venues objectAtIndex:[actionSheet tag]];
NSString *venue_address = [venues_full_address objectAtIndex:[actionSheet tag]];
NSString *venue_lat = [venues_lat objectAtIndex:[actionSheet tag]];
NSString *venue_lng = [venues_lng objectAtIndex:[actionSheet tag]];
NSLog(@"%@, %@, %@, %@", venue_title, venue_address, venue_lat, venue_lng);
NSDictionary *venue_details_dict = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:venue_title, venue_address, venue_lat, venue_lng, nil] forKeys:[NSArray arrayWithObjects:@"name", @"address", @"lat", "lng", nil]];
我在NSLog对象时看到所有正确的值,但NSDictionary使应用程序崩溃并出现EXC_BAD_ACCESS
错误。我启用了NSZombies
,但是当它经常显示崩溃时没有显示任何内容。关于这里发生了什么的任何想法?提前谢谢!
答案 0 :(得分:12)
NSDictionary *venue_details_dict = [[NSDictionary alloc] initWithObjects:
[NSArray arrayWithObjects:venue_title, venue_address, venue_lat, venue_lng, nil]
forKeys:
[NSArray arrayWithObjects:@"name", @"address", @"lat", "lng", nil]];
您忘记了@
上的"lng"
。吊杆。
答案 1 :(得分:2)
为了更清晰,可以更容易看到这样的错误:
NSDictionary *venue_details_dict = [NSDictionary dictionaryWithObjectsAndKeys:
venue_title, @"name",
venue_address, @"address",
venue_lat, @"lat",
venue_lng, @"lng",
nil];