我有以下这些在头文件中声明:
注:我不会解释整个代码,我认为它很容易理解
typedef void (^loopCell)(id cell);
-(id)allCells:(loopCell)cell;
以下是实现 allCells 函数的代码:
-(id)allCells:(loopCell)cell
{
for (AAFormSection *section in listSections)
{
for (id _cell in section.fields) {
cell(_cell);
}
}
return nil;
}
allCells函数的使用方法:-(void)setFieldValue:(NSString *)value withID:(int)rowID
{
[self allCells:^(id cell) {
if([cell isKindOfClass:[AAFormField class]]) {
AAFormField *_cell = (AAFormField *)cell;
if(_cell.rowID == rowID) {
_cell.value = value;
//return; Here I want to terminate loop
}
}
}];
}
我的问题是,我无法在中途终止 allCells 循环(实际上当我在循环中找到需要的对象时,我不想遍历其他对象)
如何在中途停止 allCells 循环?