我想使用块作为回调处理程序,但我不确定我所做的是否正确,因为我的应用程序正在崩溃。这是我正在做的事情:
在我的 FirstViewController 中,我调用 FirstModel 类的方法从服务器获取数据,如下所示:
//In FirstViewController.m
[aFirstModelObj retreiveDataWithCallBackHandler:^(NSDictionary *responseDict){
//Data is received so we can proceed...
}];
//In FirstModel.m
typedef void(^newBlock)(NSDictionary *);
newBlock theBlock;
-(void)retreiveDataWithCallBackHandler:(void(^)(NSDictionary *))aBlock
{
//Saving "aBlock" for further use..
theBlock = aBlock;
//Server Processor will retrieve data using URL asynchronously,
//initializing ServerProcessor object and providing FirstModel its delegate,so that when data is received in ServerProcessor class FirstModel's receivedResponse method will get called.
serverProcessorObj.delegate = self;
}
-(void)receivedResponse:(NSDictionary *)responseDict
{
//once data is received call block,
theBlock(responseDict);
}
我的应用程序崩溃了,因为我失去了代表。当我从 ServerProcessor 调用 [delegate receivedResponse:response] 时,它说 exc bad access。谁能告诉我做错了什么?
提前致谢!