【发布时间】:2014-05-07 01:46:08
【问题描述】:
使用继承。
我有一个子类调用父类中运行调用服务器 API 的方法。
-(IBAction)buttonPressed
{
[self methodInParentClassThatCallsTheAPI:param];
// This is where I would like the call back
if (success from the server API) // do something with the UI
else if (failure from the server API) // do so something else with the UI
}
父类:
- (void)methodInParentClassThatCallsTheAPI:(NSString *)param
{
//The method below calls the server API and waits for a response.
[someServerOperation setCompletionBlockWithSuccess:^(param, param){
// Return a success flag to the Child class that called this method
} failure:^(param, NSError *error){
// Return a failure flag to the Child class that called this method
}
}
如何使用块来完成此操作?除了块之外还有更好的方法吗?请提供代码示例
【问题讨论】:
标签: objective-c ios7 objective-c-blocks