0

我在名为 favToLoad 的 NSMutableDictionary 中有数组。我正在尝试使用 UITableView 的 indexPath.row 来一一获取数组。

代码 :

NSArray* fav = [[NSArray alloc] init];
NSLog(@"IndexPath = %d", indexPath.row);
fav = [favToLoad objectAtIndex:indexPath.row];
NSLog(@"Fav = %@", fav);

错误:

[NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance

解决方案

我通过使用 NSMutableArray 而不是 NSMutableDictionary 解决了我的问题

4

2 回答 2

4

字典没有索引。你不能这样做。相反,您需要使用 -objectForKey: 和适当的键来获取您想要的值(您可以在调试器中使用 'po favToLoad' 来检查内容)。

于 2013-02-20T22:05:38.253 回答
1

你应该使用objectForKey:而不是objectAtIndex:

objectAtIndex:NSArray班级有效

于 2013-02-20T22:34:42.420 回答