1
我想提取字典的值,但返回null。爲什麼?objectForKey返回null,但nsdictionary已滿
我的代碼:
- (void)viewDidLoad
{
//....
self.mutableArray =[[NSMutableArray alloc]init];
self.mutableDictionary =[NSMutableDictionary dictionaryWithObjectsAndKeys:@"Carrello", @"Name List", @"18", @"Number", nil];
[mutableArray addObject:self.mutableDictionary];
//....
}
後
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Login";
self.cellCustom = (CellCustomTableList*)[aTableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if(self.cellCustom == nil){
self.cellCustom = [[CellCustomTableList alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
}
NSDictionary * dictionary = [self.mutableArray objectAtIndex:indexPath.row];
NSLog(@"the dictionary %@", dictionary);
/*the dictionary {
"Name List" = Carrello;
"Number" = 18;
}*/
NSLog(@"%@", [dictionary objectForKey:@"Name List"]);
// (null)
NSLog(@"%@", [dictionary objectForKey:@"Number"]);
// (null)
NSLog(@"%@", [dictionary allKeys]);
/*(
"Name List",
"Number"
)
*/
int i =[self.mutableArray indexOfObject:dictionary];
NSLog(@"%d", i);
//0
return self.cellCustom;
}
你確定字典的nslog是唯一的嗎? – 2013-03-15 17:10:37
你似乎已經寫只是不理解的錯誤 – 2013-03-15 17:39:34
你可以告訴我的'[字典allKeys]' – 2013-03-15 17:42:01