0

プロパティを作成しNSMutableArray、値を代入するときに次のコードを作成しました

[self setTotalCells:[[NSMutableArray alloc] initWithArray:[jsonDictionary valueForKey:@"data"]]];

検索バー方式で使用しています。ただし、そのプロパティを使用すると、配列が空になります。

cells = [[NSMutableArray alloc]init];
NSLog(@"filterContentForSearchText");
NSLog(@"**************************************************************");
if ([totalCells count]<= 0) {
    totalCells = [_jsonPropertiesDictionary valueForKey:@"data"];
}
NSLog(@"%@",totalCells);
NSLog(@"**************************************************************");
for (id cell in totalCells)
{
    NSLog(@"bedrooms : %@",[cell valueForKey:@"BEDROOMS"]);
    NSLog(@"DISPLAY_ADDRESS : %@",[cell valueForKey:@"DISPLAY_ADDRESS"]);
    NSLog(@"PRICE : %@",[cell valueForKey:@"PRICE"]);
    NSLog(@"searchText : %@",searchText);
    NSComparisonResult result = NSOrderedAscending;
    if ([[cell valueForKey:@"BEDROOMS"] isKindOfClass:[NSString class]] && [[cell valueForKey:@"BEDROOMS"] length] > 0) {
        result = [[cell valueForKey:@"BEDROOMS"] compare:searchText options:(NSCaseInsensitiveSearch) range:NSMakeRange(0, [searchText length])];

        if (result == NSOrderedSame)
            [self.filteredListContent addObject:cell];
    }
    if ([[cell valueForKey:@"DISPLAY_ADDRESS"] isKindOfClass:[NSString class]] && [cell valueForKey:@"DISPLAY_ADDRESS"] != nil && [cell valueForKey:@"DISPLAY_ADDRESS"] != @"" && [[cell valueForKey:@"DISPLAY_ADDRESS"] length] > 0) {
        result = [[cell valueForKey:@"DISPLAY_ADDRESS"] compare:searchText options:(NSCaseInsensitiveSearch) range:NSMakeRange(0, [searchText length])];

        if (result == NSOrderedSame)
            [self.filteredListContent addObject:cell];
    }
    if ([[cell valueForKey:@"PRICE"] isKindOfClass:[NSString class]] && [cell valueForKey:@"PRICE"] != nil && [[cell valueForKey:@"PRICE"] length] > 0) {
        result = [[cell valueForKey:@"PRICE"] compare:searchText options:(NSCaseInsensitiveSearch) range:NSMakeRange(0, [searchText length])];

        if (result == NSOrderedSame)
            [self.filteredListContent addObject:cell];
    }
    if ([searchText isEqualToString:@"" ]) {
        filteredListContent = totalCells;
        break;
    }
}
if (self.filteredListContent.count > 0) {
    cells = self.filteredListContent;//added by prajakta
}

[self.propertyList_table reloadData];
NSLog(@"filteredListContent : %@ ",filteredListContent);

このプロパティを次のように宣言しました

@property(atomic,retain)NSMutableArray *totalCells;

どんな助けでも大歓迎です

4

1 に答える 1

0

このようにフィルタリングしないのはなぜですか?元のデータソースを台無しにすることはありません...

cells = [[NSMutableArray alloc]init];
NSLog(@"filterContentForSearchText");
NSLog(@"**************************************************************");
if ([totalCells count]<= 0) {
    totalCells = [_jsonPropertiesDictionary valueForKey:@"data"];
}
NSLog(@"%@",totalCells);
NSLog(@"**************************************************************");

/*
 * replace your code FROM here...
 */

NSArray *filteredCells = [totalCells filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
    NSDictionary *cell = (NSDictionary *)evaluatedObject;
    if ([[cell valueForKey:@"BEDROOMS"] isKindOfClass:[NSString class]] && [[cell valueForKey:@"BEDROOMS"] length] > 0) {
        return [[cell valueForKey:@"BEDROOMS"] compare:searchText options:(NSCaseInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
    }
    if ([[cell valueForKey:@"DISPLAY_ADDRESS"] isKindOfClass:[NSString class]] && [cell valueForKey:@"DISPLAY_ADDRESS"] != nil && [cell valueForKey:@"DISPLAY_ADDRESS"] != @"" && [[cell valueForKey:@"DISPLAY_ADDRESS"] length] > 0) {
        return [[cell valueForKey:@"DISPLAY_ADDRESS"] compare:searchText options:(NSCaseInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
    }
    if ([[cell valueForKey:@"PRICE"] isKindOfClass:[NSString class]] && [cell valueForKey:@"PRICE"] != nil && [[cell valueForKey:@"PRICE"] length] > 0) {
        return [[cell valueForKey:@"PRICE"] compare:searchText options:(NSCaseInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
    }
    return FALSE;
}]];

/*
 * TO here...
 */

if (self.filteredListContent.count > 0) {
    cells = self.filteredListContent;//added by prajakta
}

[self.propertyList_table reloadData];
NSLog(@"filteredListContent : %@ ",filteredListContent);
于 2013-01-28T13:11:41.343 に答える