您好,我有一个可能很简单的问题,但我还不能处理。
- 我有一个 Modelclass 'Location',它包含一个具有类别 ID(12、23、56)的数组。
- 然后我有一个包含所有可用类别 ID 的数组(1、2、3、4、5、6、7、...)
- 所有这些类别都有一个 ID,显示在 TableView 中,并且可以选择或不选择。
- 我在 MapView(注释类是位置)上显示了一组标记,应该根据在提到的 Filter TableView 中选择的过滤器来显示这些标记。
我需要实现一个“按类别过滤”功能,该功能删除所有标记并再次添加它们,但仅基于列表中的选择。
所以我需要将数组与位置模型中的过滤器 ID 与数组与 TableView 中的所有过滤器 ID 进行比较。我为此使用了以下功能:
for (Location *currLocation in arrListOfLocationsNearby) {
for (NSString *currKatId in currLocation.arrKatIds) {
NSInteger intCurrKatId = [currKatId integerValue];
NSLog(@"Current KatId %@ id: %d \n", currLocation.strAdr, intCurrKatId);
for (Filter *currFilter in [SDM getSharedDataManager].arrListOfFilterOptions) {
if (currFilter.isSelected) {
NSInteger intCurrFilterId = [currFilter.strAtt_id intValue];
NSLog(@"Current Filter %@ id: %d \n", currFilter.strAtt_text, intCurrFilterId);
if ([currKatId intValue] == [currFilter.strAtt_id intValue]) {
currLocation.isVisible = YES;
}else {
currLocation.isVisible = NO;
}
}
}
} }
我知道这将是循环遍历所有内容的最无效方法。我想以某种方式使用 NSPredicate ,但我以前从未使用过它们,而且我找不到我的问题的例子。
你们有什么提示吗?
问候米。