NSMutableArray 在发送到主线程时变为 nil

发布于 2024-12-22 15:48:31 字数 1349 浏览 4 评论 0原文

我在后台线程上有一个函数,如下所示

NSMutableArray *descriptions = [[NSMutableArray alloc] init];
NSString *description = [flickrFetcher descriptionForPhotoID:[[photos objectAtIndex:i] objectForKey:@"id"]];
    if ([description length] == 0) {
        description = @"No description available.";
    }
[descriptions addObject:description];
NSLOg(@"descriptions:%@.", descriptions);
[target performSelectorOnMainThread:action withObject:descriptions];

: 运行中:

NSLog(@"description now is:%@.", descriptions");

日志:

    Descriptions:2011-12-22 15:13:29.265 Paparazzi[3683:11903] (
    "No description available.",
    "No description available.",
    "No description available.",
    "No description available.",
     "No description available.",
     "No description available.",
    "No description available.",
    "No description available.",
    "This is a photo of just the eyes of an image I created by editing Apple's snow leopard image. I call the whole image \"Thermal Leopard\"."
).

descriptions:(null).

在该函数中,描述(数组)始终以 nil 结尾。为什么会发生这种情况?

编辑1:

我第二次调用这个函数时,数组不为零,并且一切都按预期工作。这只是第一次调用此代码。另外,它仅在主线程操作方法中为 nil,而不是在上面所示的代码中。

编辑2:

这是一个错误吗?我应该将其提交给Apple吗? 我认为这可能不是我的错,如果我能得到关于这是否是错误的建议那就太好了。

I have a function on a background thread that looks like this:

NSMutableArray *descriptions = [[NSMutableArray alloc] init];
NSString *description = [flickrFetcher descriptionForPhotoID:[[photos objectAtIndex:i] objectForKey:@"id"]];
    if ([description length] == 0) {
        description = @"No description available.";
    }
[descriptions addObject:description];
NSLOg(@"descriptions:%@.", descriptions);
[target performSelectorOnMainThread:action withObject:descriptions];

In action:

NSLog(@"description now is:%@.", descriptions");

Logs:

    Descriptions:2011-12-22 15:13:29.265 Paparazzi[3683:11903] (
    "No description available.",
    "No description available.",
    "No description available.",
    "No description available.",
     "No description available.",
     "No description available.",
    "No description available.",
    "No description available.",
    "This is a photo of just the eyes of an image I created by editing Apple's snow leopard image. I call the whole image \"Thermal Leopard\"."
).

descriptions:(null).

In that function, descriptions (the array) always ends up as nil. Why is this happening?

EDIT 1:

The second time I call this function, the array is not nil and every thing works as expected. It is just the first time this code is called. Also, it is only nil in the main thread action method, not in the code shown above.

EDIT 2:

Is this a bug? Should I submit it to Apple?
I think this might not be my fault, if I could get suggestions on wether this is a bug or not that would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巷子口的你 2024-12-29 15:48:31

我发现了问题所在。在操作方法的某个地方,我发现我将描述设置为nil。非常感谢大家的帮助。我对您的所有回答和评论表示感谢。

I figured out the problem. Somewhere in the action method, I found that I was setting description to nil. Thank you all soooo much for your help. I am upvoting all of your answers and comments to thank you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文