简体   繁体   English

EXC_BAD_ACCESS与NSDictionary

[英]EXC_BAD_ACCESS with NSDictionary

I'm trying to add objects that are in an array to an NSDictionary based on their position inside of the NSArray , but the app crashes as soon as the NSDictionary is allocated. 我正在尝试根据它们在NSArray的位置将数组中的对象添加到NSDictionary ,但是一旦分配了NSDictionary ,应用程序就会崩溃。 Any ideas why? 有什么想法吗?

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]];

I see all the right values when I NSLog the objects, but the NSDictionary makes the app crash with a EXC_BAD_ACCESS error. 我在NSLog对象时看到所有正确的值,但NSDictionary使应用程序崩溃并出现EXC_BAD_ACCESS错误。 I have NSZombies enabled, but nothing is being shown when it crashes like it would regularly show. 我启用了NSZombies ,但是当它像经常显示的那样崩溃时没有显示任何内容。 Any ideas on what's going on here? 关于这里发生了什么的任何想法? Thanks in advance! 提前致谢!

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]];

You forgot the @ on "lng" . 你忘记了"lng"上的@ Boom. 繁荣。

For more clarity that makes errors like this easier to see try: 为了更加清晰,可以更容易地看到这样的错误:

NSDictionary *venue_details_dict = [NSDictionary dictionaryWithObjectsAndKeys:
    venue_title,   @"name",
    venue_address, @"address",
    venue_lat,     @"lat",
    venue_lng,     @"lng",
    nil];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM