【发布时间】:2015-06-11 14:34:53
【问题描述】:
与我一起工作的人不想使用委托方法有几个原因,他们希望我想出一个解决方案;
基本上他们想要一个带有多个返回值的回调块,当第一个返回值到达时,块仍然应该等待即将到来的返回值
类似
[parserobject parsefile:file withCallback {
if (started) {
//file parsing started
//this should get executed first
}
//if file parsing succesfully started also check if it
//succesfully finished or failed in the same callback
if (finished) {
//file parsing finished
}
if(failed)
{
//this represents if parsing failed any time from start to finish
//if so exit the callback
}
}];
我见过有人使用structs 或nsintegers 来返回不同的值,但通常只返回一个结果......
上面的代码块可以用objective-c编写吗?
【问题讨论】:
-
您想收到每次更新的通知吗?
-
是的,但在同一个回调函数中
-
你试过
NSNotification吗? -
我会创建一个块,只要内部状态发生变化,它就会被 parsefile 调用。将状态作为参数传递给块。即 block(PARSE_STARTED), block(PARSE_FINISHED), block(PARSE_FAILED)... FINISHED 或 FAILED 表示两种方式都已完成。
标签: ios objective-c callback block