gpt4 book ai didi

ios - -[__NSCFDictionary objectAtIndex :]:

转载 作者:行者123 更新时间:2023-12-02 03:02:55 27 4
gpt4 key购买 nike

救命!我已经为这个问题苦恼了 1 个小时了。

我正在我的 .h 文件中创建一个数组

    @interface LeftMenuViewController : UIViewController <UITableViewDataSource, UITabBarControllerDelegate>

@property (strong, nonatomic) MKNetworkOperation *myNetworkOperation;
@property (strong, nonatomic) NSArray *listOfClubsArray;

@end

然后,我从 JSON 格式的 API 调用中提取项目列表

///////////////////////////////////////////
#pragma mark Retreive List of Clubs / Teams
///////////////////////////////////////////

- (void)getListOfClubs {

// Because we have a success from login auth we will now make a seperate call to gather club details

self.myNetworkOperation = [app.teamManagerWrapper deviceID:@"adam" userToken:@"sdfdfgf" onCompletion:^(NSDictionary *result) {

NSDictionary *data2 = [result objectForKey:@"data"];

self.listOfClubsArray = [data2 objectForKey:@"user_clubs"];

[self.tableView reloadData];

} onError:^(NSError *error) {

// error none

}];

JSON 看起来像这样

{
"code": 200,
"data": {
"user_clubs": {
"5238": {
"club_id": "45484",
"name": "Testing This Club Name",
"sport_id": "7",
"primary_colour": "#000000",
"secondary_colour": "#f15729",
"members": null,
"sections": {
"s": "Mens",
"j": "Junior",
"m": "Summer League",
"l": "Ladies"
}

我的表格单元看起来像这样

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ClubCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell==nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

NSDictionary *tempDictionary= [self.listOfClubsArray objectAtIndex:indexPath.row];

cell.textLabel.text = [tempDictionary objectForKey:@"name"];

return cell;
}

这条线崩溃了

NSDictionary *tempDictionary= [self.listOfClubsArray objectAtIndex:indexPath.row];

使用此崩溃日志

2013-11-19 12:13:43.069 Manager App[11394:70b] -[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x8b0e9d0
2013-11-19 12:13:43.071 Manager App[11394:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x8b0e9d0'
*** First throw call stack:

非常感谢任何帮助!!

最佳答案

在您的 JSON 示例中,没有俱乐部数组,而是字典,因此 objectAtIndex 将不起作用。

{
"code": 200,
"data": {
"user_clubs": {
"5238": {
"club_id": "45484",
"name": "Testing This Club Name",

在这里您可以看到 data/user_clubs 包含一个字典,如果您想要测试此俱乐部名称,您可以使用它的键来获取它:

 NSDictionary *tempDictionary= [self.listOfClubsArray objectForKey:@"5238"];

现在这不是您想要的,解决方案可能是:

NSArray *keys = [self.listOfClubsArray allKeys];
NSString *key = [keys objectAtIndex:indexPath.row];
NSDictionary *tempDictionary= [self.listOfClubsArray objectForKey:key];

但请确保您还告诉 UITableView 正确的键数并更改

@property (strong, nonatomic) NSArray *listOfClubsArray;

@property (strong, nonatomic) NSDictionary *listOfClubsArray;

关于ios - -[__NSCFDictionary objectAtIndex :]:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20071524/

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