内部块= EXC_BAD_ACCESS [英] Block inside block = EXC_BAD_ACCESS

查看:39
本文介绍了内部块= EXC_BAD_ACCESS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单例课程,负责处理所有Game Center逻辑:

I have a singleton class the handle all the Game Center logic:

typedef void (^GameCenterCallbackFinishUpdating)();

- (void)getAllMatches:(GameCenterCallbackFinishUpdating)onComplete
{
    [GKTurnBasedMatch loadMatchesWithCompletionHandler:^(NSArray *matches, NSError *error)
    {      
        //Do stuff here... 
        onComplete();
    }];
}

我使用另一个viewController:

From another viewController I use:

[[GameCenterHelper sharedHelper] getAllMatches:^{

    [self.myTableView reloadData]; 

}];

当我在应用程序中时,它的工作效果很好,但是一旦我关闭了该应用程序(后台),然后再次启动它,我就会得到:

It works great when I'm in the app, but once I close the app (background) and then start it up again, I get:

    onComplete();     ---- Thread 1: EXC_BAD_ACCESS (code=2, address=0xc)

我在这里做错了什么?

推荐答案

一些背景信息:这些块是对象,如果有任何块 nil ,然后您尝试调用它们,这会使应用程序崩溃.

some background info: the blocks are objects and if any block is nil and you try to call them, it crashes the application.

在调用某个地方之前,该地方 onComplete 会以某种方式变为 nil .以下 if(...)语句可帮助您防止调用 nil 指针,因此应用程序不会崩溃.

somewhere and somehow the block onComplete becomes nil before you call it. the following if (...) statement helps you to prevent to call a nil pointer, so the application won't crash.

if (onComplete) onComplete();

这篇关于内部块= EXC_BAD_ACCESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆