gpt4 book ai didi

ios - 尝试从字典中检索字符串时出现 "[__NSArrayM objectForKey:]: unrecognized selector"

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:41:32 27 4
gpt4 key购买 nike

我正在尝试为我的标签设置文本。这是代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
newsDataCell *cell = (newsDataCell*)[tableView dequeueReusableCellWithIdentifier:@"newsData"];

if (cell == nil)
{
cell = [[newsDataCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"newsData"];
}

NSDictionary* currentrow =[self.Items objectAtIndex:indexPath.item];
NSLog(@"currentrow:%@",currentrow);
//UIImageView *image = (UIImageView*)[cell viewWithTag:0];

UILabel *txtData = (UILabel*)[cell viewWithTag:1];
NSString *testo = [currentrow objectForKey:@"Date"];
[txtData setText:testo];


UILabel *txtTitolo = (UILabel*)[cell viewWithTag:2];
txtTitolo.text =[currentrow valueForKey:@"Title"];

UILabel *txtDescrizione = (UILabel*)[cell viewWithTag:3];
txtDescrizione.text = [currentrow valueForKey:@"Descr"];

return cell;
}

我检查过,currentrow 确实包含该对象。这是我从 Xcode 得到的错误:

2013-09-11 16:04:36.468 ApplicationName[2409:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]:unrecognized selector sent to instance 0x7172f80'*** First throw call stack:(0x1333012 0x1158e7e 0x13be4bd 0x1322bbc 0x132294e 0xc5f4 0x1578fb 0x1579cf 0x1401bb 0x150b4b 0xed2dd 0x116c6b0 0x265bfc0 0x265033c 0x2650150 0x25ce0bc 0x25cf2270x25cf8e2 0x12fbafe 0x12fba3d 0x12d97c2 0x12d8f44 0x12d8e1b 0x22757e3 0x2275668 0x9cffc 0x2c2d 0x2b55)libc++abi.dylib: terminate called throwing an exception

我在使用 valueForKey 时遇到同样的错误:

txtTitolo.text =[currentrow valueForKey:@"Title"];

这里是:

2013-09-11 16:09:34.478 ApplicationName[2409:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM valueForKey:]:unrecognized selector sent to instance 0x7172f80'*** First throw call stack:(0x1333012 0x1158e7e 0x13be4bd 0x1322bbc 0x132294e 0xc5f4 0x1578fb 0x1579cf 0x1401bb 0x150b4b 0xed2dd 0x116c6b0 0x265bfc0 0x265033c 0x2650150 0x25ce0bc 0x25cf2270x25cf8e2 0x12fbafe 0x12fba3d 0x12d97c2 0x12d8f44 0x12d8e1b 0x22757e3 0x2275668 0x9cffc 0x2c2d 0x2b55)libc++abi.dylib: terminate called throwing an exception

怎么了?

最佳答案

看起来 currentrow 不是 NSDictionary(您假设的)。它是一个 NSArray

NSDictionary* currentrow =[self.Items objectAtIndex:indexPath.item];
// Not a dictionary, it is an array.

这就是您遇到此崩溃的原因。如果这是经过解析的 JSON 响应,请检查 JSON 的结构。

希望对您有所帮助!

关于ios - 尝试从字典中检索字符串时出现 "[__NSArrayM objectForKey:]: unrecognized selector",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18743889/

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