2011-06-15 54 views
5

我試圖根據它們在NSArray之內的位置將數組中的對象添加到NSDictionary,但是應用程序在NSDictionary分配後立即崩潰。任何想法爲什麼?EXC_BAD_ACCESS with 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

請粘貼崩潰報告的文本和任何上述錯誤信息到你的問題。 – 2011-06-15 22:48:27

回答

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"。繁榮。

+0

哇。如此愚蠢。我無法相信我沒有注意到這一點。謝謝! – 2011-06-15 22:50:39

+0

這也適用;-) NSDictionary * venue_details_dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:venue_title,venue_address,venue_lat,venue_lng,nil] forKeys:[NSArray arrayWithObjects:@「name」,@「address」,@「lat 「,@」lng「,nil]]; – 2011-06-15 22:55:52

+1

請提交一個錯誤 - 編譯器應該能夠捕捉到這個錯誤。 – bbum 2011-06-15 23:00:05

2

爲了更清楚,讓這樣的錯誤更容易地看到嘗試:

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