开发者

App crashes when accessing NSDictionary's values but not when accessing its keys?

I have an NSDictionary object called "myData," and I'm trying to access it from the UITableViewDelegate method "didSelectRowAtIndexPath."

I can perform these operations fine:

if(myData == nil) { /* it doesn't print here, so it's not nil */ }
NSLog(@" * Keys: %@", [myData allKeys]); // Outputs all of the keys.

But if I try to perform any of THESE operations, the App crashes with no warnings, errors, or output of any k开发者_如何转开发ind:

[myData objectForKey:@"akey"];
[myData allValues];

Anybody have an idea what may be causing this?


Sounds like myData was does not contain a valid reference. Do you release it or forgot to retain it after reading?

[Update]: To be on the safe side and exclude this just do one more retain after creating the dictionary (just for testing!) and check whether the crash disappears. If not maybe some other variable is overwriting your myData. Set two breakpoints, one at point where the dictionary is assigned to myData, the other one before the point of crash. Check if you see a reasonable summary e.g. "2 keys pairs".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜