gpt4 book ai didi

iphone - NSMutableArray 和 NSDictionary 错误

转载 作者:行者123 更新时间:2023-12-03 20:45:48 26 4
gpt4 key购买 nike

我有一个名为 SubList 的 NSMutableArray,其中包含 262 个元素。每个对象都是一个 NSDictionary!

这段代码就像一个魅力!

for (NSDictionary *element in listSub){
[cell.textLabel setText:[element objectForKey:@"title"]];

}

但是如果我尝试使用此代码,我会收到 SIGBART 错误!

NSDictionary * element = [listSub objectAtIndex:[indexPath row]];

[cell.textLabel setText:[element objectForKey:@"title"]];

那么问题出在哪里呢?

*编辑问题出在这一行

NSDictionary * element = [listSub objectAtIndex:[indexPath row]];

这是描述由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFSet objectAtIndex:]:无法识别的选择器发送到实例 0x89a8d90”谢谢

**编辑这是 listSub 的输出!

listSub: {(
{
categories = (
{
id = "user/14761688561595773457/label/Web Programming";
label = "Web Programming";
}
);
firstitemmsec = 1265885595862;
id = "feed/http://feeds.feedburner.com/FamousBloggers";
sortid = A11327DE;
title = "Famous Bloggers";
},
{
categories = (
{
id = "user/14761688561595773457/label/Hacking";
label = Hacking;
}
);
firstitemmsec = 1241258413829;
htmlUrl = "http://backtrack-italia.blogspot.com/";
id = "feed/http://feeds2.feedburner.com/BackTrackItalia";
sortid = E8A04F76;
title = "Back Track Italia";
},
{
categories = (
{
id = "user/14761688561595773457/label/Hacking";
label = Hacking;
}
);
firstitemmsec = 1245376992188;
htmlUrl = "http://www.offensive-security.com";
id = "feed/http://www.offensive-security.com/blog/feed/";
sortid = 92F57555;
title = "BackTrack Information Security Distribution";
},
{
categories = (
{
id = "user/14761688561595773457/label/iOS Developer";
label = "iOS Developer";
}
);
firstitemmsec = 1296830392306;
htmlUrl = "http://amix.dk/Main/";
id = "feed/http://feeds.feedburner.com/amixdk";
sortid = 110C52C3;
title = "amix.dk blog";
},
{
categories = (
{
id = "user/14761688561595773457/label/Apple News";
label = "Apple News";
}
);
firstitemmsec = 1285261350202;
htmlUrl = "http://www.appletvhacks.net";
id = "feed/http://www.appletvhacks.net/feed/";
sortid = 81125D2E;
title = "Apple TV Hacks";
},
{
categories = (
{
id = "user/14761688561595773457/label/Apple News";
label = "Apple News";
}
);
firstitemmsec = 1293230300220;
htmlUrl = "http://www.appletvitalia.it";
id = "feed/http://www.appletvitalia.it/feed/";
sortid = 892FE61C;
title = "Apple Tv Italia";
},
{
categories = (
{
id = "user/14761688561595773457/label/Apple News";
label = "Apple News";
}
);
firstitemmsec = 1270115980935;
htmlUrl = "http://www.appleecious.com";
id = "feed/http://feeds2.feedburner.com/appleecious";
sortid = 00B5AFC2;
title = Appleecious;
},
{
categories = (
{
id = "user/14761688561595773457/label/Hacking";
label = Hacking;
}
);
firstitemmsec = 1258495136927;
htmlUrl = "http://www.rawseo.com/news";
id = "feed/http://www.rawseo.com/news/feed/";
sortid = D6766911;
title = "A blend of programming and seo";
},
{
categories = (
{
id = "user/14761688561595773457/label/Seo e Web Marketing";
label = "Seo e Web Marketing";
}
);
firstitemmsec = 1233684720758;
htmlUrl = "http://it-adsense.blogspot.com/";
id = "feed/http://it-adsense.blogspot.com/atom.xml";
sortid = 9FB570ED;
title = "AdSense Blog-Italiano";
},
{
categories = (
);
firstitemmsec = 1277627346000;
htmlUrl = "http://aext.net";
id = "feed/http://feeds.feedburner.com/aextnet";
sortid = 70800CFE;
title = "AEXT.NET NET MAGAZINE";
},
{
categories = (
);
firstitemmsec = 1217001547735;
htmlUrl = "http://www.alessandroscoscia.it";
id = "feed/http://feeds.feedburner.com/alessandroscoscia";
sortid = 51CB8E6E;
title = "Alessandro Scoscia";
},
{
categories = (
{
id = "user/14761688561595773457/label/iOS Developer";
label = "iOS Developer";
}
);
...

我确定它不是 NSSet。

现在我发布用于填充数组的代码。

 NSError *error;
NSURLResponse *response;
NSData *dataReply = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
NSString *string = [[NSString alloc] initWithData:dataReply encoding:NSASCIIStringEncoding];
NSLog(@"testing %@",string);


SBJsonParser *vol= [[SBJsonParser alloc]init];
if (string) {
NSArray *feeds = [vol objectWithString:string error:nil];
NSDictionary *results = [string JSONValue];
NSArray *subs = [results valueForKey:@"subscriptions"];

for (NSDictionary *iscrizione in subs){

[subscriptions addObject:iscrizione];

}

这是另一个类的一部分,如果我尝试做这样的事情,也在我的代码的这一部分中:NSDictionary * element = [listSub objectAtIndex:0];NSLog([元素 objectForKey:@"title"]);

如果我尝试这样的循环,我会得到同样的错误

for (NSDictionary *element in listSub){
[cell.textLabel setText:[element objectForKey:@"title"]];

}

一切正常,没有 NSSet 错误。这让我发疯!

最佳答案

问题可能是 listSub 没有正确保留,因此已经被释放。内存现在被重新使用,并且该地址处的对象现在是一个 __NSCFSet,它不会响应 objectAtIndex:

请注意,由诸如 [NSMutableArray arrayWithXXX] 之类的便利类方法返回的自动释放对象应保留,并且仅在不再需要时释放。确保保留它们的最佳方法是声明一个 @property(retain) NSArray *subList@synthesize 并使用 self.subList 在所有情况下,除了在 dealloc 中。

添加

有人建议创建 subList 的方法返回一个集合而不是数组。如果是这样的话,答案开头的简单循环也将不起作用。这就是为什么我发现 subList 最初不太可能是 NSSet,更有可能的是该数组被过度释放和释放,并且内存重新用于 >NSSet.

请按照那些想要帮助您的人的要求去做

添加行

NSLog(@"listSub: %@", listSub);

在设置listSub的地方,也在错误行之前。然后查看错误日志中显示的内容并告诉我们。

关于iphone - NSMutableArray 和 NSDictionary 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7201890/

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