2011-10-13 32 views
6
-(id)init{ 
    if (self==[super init]) {    
     NSMutableArray *listname = [[NSMutableArray alloc]initWithObjects:@"cu",@"al",@"zn",@"au",@"ru",@"fu",@"rb",@"pb",@"wr", nil];    
     NSMutableArray *listVolumn = [NSMutableArray arrayWithCapacity:[listname count]];   
     for (int i=0; i<[listname count]; i++) { 
      [listVolumn addObject:[NSNumber numberWithLong:0]]; 
     } 
     nsmutabledictionary = [[NSDictionary alloc] initWithObjects:listVolumn forKeys:listname]; 
    } 
    return self; 
} 

trong phương pháp init của tôi, tôi đã xác định hai NSMutableArray và được thêm vào NSMutableDictionary nsmutabledictionary. trong phương pháp khác của tôi:[__NSCFDictionary setObject: forKey:]: phương pháp thay đổi được gửi đến đối tượng bất biến

[nsmutabledictionary setObject:[NSNumber numberWithLong:100] forKey:@"cu"]; 

nhưng nó sụp đổ tại dòng trên: enter image description here

Trả lời

16
nsmutabledictionary = [[NSDictionary alloc] initWithObjects:listVolumn forKeys:listname]; 

nên

nsmutabledictionary = [[NSMutableDictionary alloc] initWithObjects:listVolumn forKeys:listname]; 
+0

cảm ơn bạn, bạn đang đúng – Gaojian922188

2

Trong mã của bạn tôi thấy rằng nsmutabledictionary = [[NSDictionary alloc] initWithObjects:listVolumn forKeys:listname]; rằng dòng bạn tuyên bố nó là NSDictionary trong khi bạn đã định nghĩa nó là NSMutableDictionary

+0

cảm ơn bạn rất nhiều, bạn đã đúng. – Gaojian922188

Các vấn đề liên quan