开发者

setObject:ForKey: crash?

I am getting this crash in the console:

2011-08-27 23:26:45.041 App[1672:3117] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil key'
*** First throw call stack:
(0x3231c8c3 0x362ee1e5 0x3231c7bd 0x3231c7df 0x32289679 0x3052e865 0x3220fd55 0x3221b7a3 0x3345e4b7 0x3345e38c)
terminate called throwing an exception[Switching to process 10243 thread 0x2803]
[Switching to process 10243 thread 0x2803]

The only line that I think would fire at the time it crashes that relates to this crash is this line:

UIImage *photo = [self.selectedDictionary objectForKey:@"ProfileImage"];

Does anything look wrong here? What could be the problem?

Edit1: It is crashing when I do this to call a method: Code:

if(actionSheet.tag == 1) {
            [self showAchievements];
        }

This is the showAchievements method: Code:

- (void)showAchievements {
    GKAchievementViewController *achievements = [[GKAchievementViewController alloc] init];
    if (achievements != nil)
    {
        achievements.achievementDelegate = self;
        [self presentModalViewController:achievements animated:YES];
    }
}

- (void)achievementViewControllerDidFinish:(GKAchievementViewController *)viewController
{
    [self dismissModalViewControllerAnimated:YES];
    [viewController release];
}

Can this crash be because I have not properly hooked everything up in iTC? I am definitely sure it crashes in that method and I do not know why.

Does anyone have any ideas?

Edit2: I am getting down to it here, in my console, right before it crashes it has a line saying Missed Method. So I search for where this NSLog is and it is in GameCenterManager.m, a file necessary for Game Center I think. Here is the method:

    - (void) callDelegate: (SEL) selector withArg: (id) arg error: (NSError*) err
{
    assert([NSThread isMainThread]);
    if([delegate respondsToSelector: selector])
    {
        if(arg != NULL)
        {
            [delegate performSelector: selector withObject: arg withObject: err];
        }
        else
        {
            [delegate performSelector: selector withObject: err];
        }
    }
    else
    {
        NSLog(@"Missed Method");
    }开发者_高级运维
}

So from that code do you see whats wrong?

Thanks!


I'd guess the answer is right there in the code you posted:

reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil key'

You can't insert a nil key into a dictionary. Are you doing something like [myDictionary setObject:foo forKey:bar] where 'bar' is nil?

Incidentally, you also can't insert nil values into a dictionary, but that doesn't appear to be what the error reason indicates. You can call [myDictionary setValue:nil forKey:bar] (as long as bar isn't nil) - this removes the key from the dictionary. And if you want to indicate a "nil" value, you can insert the NSNull object into a dictionary. But keys -- keys must always be non-nil.


From the log it seems like the key profileImage equals nil which means that there is no data for that key in your NSDictionary.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜