Objective c NSMutableArray快速搜索/
我有一个NSMutableArray,其中包含以下对象:Objective c NSMutableArray快速搜索/,objective-c,nsmutablearray,Objective C,Nsmutablearray,我有一个NSMutableArray,其中包含以下对象: @interface MyViewCell : UITableViewCell { NSUInteger id; ..... } 在某些方法中,我需要使用预定义id快速搜索单元格。如何最好地执行此操作 最简单的方法可能是使用-(NSUInteger)indexOfObjectPassingTest:(BOOL(^)(id obj,NSUInteger idx,BOOL*stop))谓词。见文件 当我尝试代码时,
@interface MyViewCell : UITableViewCell {
NSUInteger id;
.....
}
在某些方法中,我需要使用预定义id快速搜索单元格。如何最好地执行此操作 最简单的方法可能是使用
-(NSUInteger)indexOfObjectPassingTest:(BOOL(^)(id obj,NSUInteger idx,BOOL*stop))谓词
。见文件
当我尝试代码时,我遇到了一个小问题。下一个调整代码对我来说很好(*停止):
谢谢我怎样才能找到MyViewCell?据我所知,它只是在搜索预定义的id。
[myArray objectAtIndex:index]
int index = [myArray indexOfObjectPassingTest: ^(id obj, NSUInteger idx, BOOL *stop) {
MyViewCell *cell = (MyViewCell *)obj;
BOOL result = (cell.id == someValue);
stop = &result;
return result;
}];
int index = [myArray indexOfObjectPassingTest: ^(id obj, NSUInteger idx, BOOL *stop) {
MyViewCell *cell = (MyViewCell *)obj;
BOOL result = (cell.id == someValue);
*stop = result;
return result;
}];