gpt4 book ai didi

ios - objectForKey 返回 null 但 nsdictionary 已满

转载 作者:行者123 更新时间:2023-11-29 13:17:10 24 4
gpt4 key购买 nike

我想提取字典的值但是返回null。为什么?

我的代码:

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

}

最佳答案

如果你的 tableView 中有更多行,你的字典中有对象,只需像这样进行简单检查:

//if you want some specific object
NSUInteger objIdx = [self.mutableArray indexOfObject: someObject];
if(objIdx != NSNotFound) {
// Do some alter stuff here
}

//or simple checking
if (indexPath.row <= [self.mutableArray count]){
// Do some alter stuff here
}

关于ios - objectForKey 返回 null 但 nsdictionary 已满,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15438223/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com