2011-10-13 6 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; 
} 

mi metodą init I określonych dwa NSMutableArray i dodano do NSMutableDictionary NSMutableDictionary. w moim innym sposobem:[__NSCFDictionary setObject: forKey:]: Metoda mutacji wysyłane do niezmiennej obiektu

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

ale krach w powyższej linii: enter image description here

Odpowiedz

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

powinny być

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

dziękuję, masz rację – Gaojian922188

2

W kodzie widzę, że nsmutabledictionary = [[NSDictionary alloc] initWithObjects:listVolumn forKeys:listname]; że wiersz, który oświadczył, to jest NSDictionary, podczas gdy ty zamierzasz NSMutableDictionary

+0

dziękuję bardzo, masz rację. – Gaojian922188

Powiązane problemy