在我的 iPhone 应用程序中,我试图在 Tableview 中实现 UISearchBar

In my iPhone app,i am trying to implement a UISearchBar in Tableview

当数组中的搜索值得到 <__NSArrayM:> 时,在枚举时发生了变异。我正在使用此代码。

NSInteger strlen=[searchText length];


for (NSString *pStr in pArrBusinessName ) {

    NSRange nameRange = [pStr rangeOfString:searchText options:NSCaseInsensitivePredicateOption];

    if(nameRange.location != NSNotFound) {

        if (strlen == 1) {
            pArrFilteredTableData = pArrBusinessName;
        } else {

            if ([pStr isKindOfClass:[NSNull class]]) {
                NSLog(@"NSNull isKindOfClass called!");
            }


            if (![pStr isKindOfClass:[NSNull class]]) {

                [pArrFilteredTableData addObject:pStr];

            }
        }

    } else {

        if ([pArrFilteredTableData count] == 0) {

        }

    }

    [pTblDetails reloadData];
}

看来你是在修改主数组的同时搜索其中的内容。如果您将搜索结果保存在一个单独的可变数组中而不是改变您创建列表所使用的主数组,那将会很好。从主数组中过滤搜索到的记录并将它们保存在搜索数组中。

更改此代码:

pArrFilteredTableData = pArrBusinessName;

对此;

pArrFilteredTableData = [pArrBusinessName mutableCopy];

确保 pArrFilteredTableData 是一个 NSMutableArray,如果它还没有的话