search bar with table view in ios

83 views Asked by At

I got error in NSPredicate

"*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "title tcontains[cd] %@"'
*** First throw call stack:
(0x15d6012 0x13fbe7e 0xe14355 0xe14173 0xe14127 0x5b68 0x5deb 0x626ff3 0x576c86 0x140f705 0x343213 0x404c7e 0x404310 0x41113c 0x41b5a6 0xebc4f9 0x16300c5 0x158aefa 0xdf0bb2 0x406e9de 0x31bc1da 0x35f5dfc 0x35f8bf8 0x4049612 0x404974a 0x4049ec0 0x4049cb8 0x4049204 0x343722b 0x3437193 0x401be96 0x40484cc 0x35f3136 0x35f23c6 0x3625980 0x3c817fd 0x361c576 0x361d6da 0x361b72e 0x3c7feaa 0x3635af1 0x362572a 0x35f96ae 0x31f862b 0x140f6b0 0x4064810 0x32371a4 0x32392ff 0x5010b4 0x4c3aef 0x4c4e58 0x4c39fe 0x4cdd29 0x350ddb 0x44e7f5 0x44e7f5 0x44e7f5 0x44e7f5 0x44e7f5 0x44e7f5 0x44e7f5 0x44e7f5 0x44e7f5 0x44e7f5 0x350e35 0x350806 0x350beb 0x342698 0x22fcdf9 0x22fcad0 0x154bbf5 0x154b962 0x157cbb6 0x157bf44 0x157be1b 0x22fb7e3 0x22fb668 0x33fffc 0x201d 0x1f45)
libc++abi.dylib: terminate called throwing an exception"

Please help me.

Here is the my code

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{

    [searchResults removeAllObjects];

    NSString *str1 = [searchText stringByReplacingOccurrencesOfString:@"\"" withString:@""];
    NSLog(@"data_arra==>%@",arr_search);
    NSLog(@"searchText==>%@",searchText);

    NSPredicate *resultPredicate = [NSPredicate
                                    predicateWithFormat:@"title tcontains[cd] %@",
                                    str1];
    NSLog(@"result==>%@",resultPredicate);

    searchResults = [NSMutableArray arrayWithArray:[arr_search filteredArrayUsingPredicate:resultPredicate]];
}


array value for arr_search 

arr_search ==>(
    "Phoenix Market City",
    "Express Avenue",
    "Ampa Skywalk",
    "The Forum Vijaya Mall",
    "Chennai Citi Centre",
    "Spencer Plaza",
    "Chandra Metro Mall",
    "The Grand Mall",
    "Ramee Mall",
    "Alsa Mall",
    "Prince Plaza",
    "Ispahani Centre",
    "Fountain Plaza",
    Lifestyle,
    "Grand Venus Spectrum Mall",
    "Raahat Palaza",
    "Patni Plaza",
    "Maya Plaza",
    "Phoenix Mall, Chennai",
    Megamart,
    "Phoenix marketcity",
    Aldo,
    "Gokul Arcade",
    "Parsn Complex",
    "Spectrum mall",
    "Express Avenue Chambers",
    "Big Bazaar",
    "Spencer's",
    "Saravana Stores",
    "CEX (complete entertainment exchange)"
)
1

There are 1 answers

4
Baby Groot On BEST ANSWER

I think it's typo error in this

NSPredicate *resultPredicate = [NSPredicate
                                    predicateWithFormat:@"title tcontains[cd] %@",
                                    str1];

It should be

NSPredicate *resultPredicate = [NSPredicate
                                    predicateWithFormat:@"title contains[cd] %@",
                                    str1];