通过 NSArray 搜索 post 到 Tableview

Searching thru NSArray to post to Tableview

我有一个加载了对象的 NSArray(见下文)。我需要将这些加载到一个表视图中,基于从另一个表视图中单击 indexpath.row。

如果用户选择 indexpath.row = 0,则第二个表视图将重新加载 ORDER_CODE,其中仅包含 GROUP = 0。 如果用户选择 indexpath.row = 1,则第二个表视图将重新加载 ORDER_CODE,其中仅包含 GROUP = 1.

任何人 advice/coding 关于如何搜索数组并将相关数据显示到第二个表格视图中的任何人?

array=(
        {
        GROUP = 0;
        "ORDER_CODE" = 410;
        "PROD_DESCR" = "cement";
        id = 0;
    },
        {
        GROUP = 0;
        "ORDER_CODE" = 411;
        "PROD_DESCR" = "concrete";
        id = 1;
    },
        {
        GROUP = 1;
        "ORDER_CODE" = 405;
        "PROD_DESCR" = "asphalt";
        id = 2;
    })

尝试使用以下代码从给定数组

中过滤结果(单击特定表格行)
NSArray *array; //your data array

//create a search predicate to filter the array
NSPredicate *searchPredicate = [NSPredicate predicateWithBlock:^BOOL(NSDictionary * evaluatedObject, NSDictionary *bindings) {

    BOOL isValidGroup = [evaluatedObject[@"GROUP"] integerValue] == indexPath.row;
    return isValidGroup;
}];

NSArray *filteredArray = [array filteredArrayUsingPredicate:searchPredicate]; //this is the filtered array you can use for the displaying in the table