开发者

Blocks for beginWithCompletionHandler from NSOpenPanel

i'm using beginWithCompletionHandler of NSOpenPanel class. My problem is that projects attribute is an invalid object inside that block. What i'm missing?

 NSOpenPanel *panel = [NSOpenPanel openPanel];
    [panel setCanChooseDirectories:NO];
    [panel setAllowedFileTypes:[NSImage imageFileTypes]];

    [panel  beginWithCompletionHandler:^(NSInteger result)
    {
        if (result==NSFileHandlingPanelOKButton)
        {
            NSString *name = [panel.URL lastPathComponent];

            NSImage *aImage = [[NSImage alloc] initWithContentsOfURL:panel.URL];

            if (aImage)
            {
                DLog(@"Success: %@", name);
                Sprite *sprite = [[Sprite alloc] init];
                [self.project addSprite:sprite];
            }
            else
            {
                DLog(@"Error, i can't load image %@ at path %@", name, [panel.URL path]);
            }
        }

    }];

I explain my problem with debugger screenshots

Before block

http://img233.imageshack.us/img233/8982/schermata062455735alle1.png

At this point all is correct, self=SpriteAnimation, project points to the correct Project instance.

http://img838.imageshack.us/img838/8982/schermata062455735alle1.png

After开发者_如何学编程 the if this is the state

http://img855.imageshack.us/img855/8982/schermata062455735alle1.png


What is the exact error message and what is going wrong?

            [self.project addSprite:sprite];
            [p addSprite:sprite];

Both p and self.project will be the same object (unless you've done something elsewhere to re-assign project between the time p was assigned and that block was run.

Note that you are also leaking the objects referred to be sprite and aImage.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜