开发者

Search Bar Controller - Crash When Searching for Results

开发者 https://www.devze.com 2023-04-09 12:03 出处:网络
I am implementing a search bar controller to search a table view. The below method code which performs the search is crashing with the error \"-[__NSArrayM rangeOfString:options:]: unrecognized select

I am implementing a search bar controller to search a table view. The below method code which performs the search is crashing with the error "-[__NSArrayM rangeOfString:options:]: unrecognized selector sent to instance 0x65558e0'

The locationInfo array is an array containing 26 arrays, each of which contains a number of objects made up of strings.

Can anyone suggest why the code is crashing ?

Thank you.

- (void)handleSearchForTerm:(NSString *)searchTerm
{
[self setSavedSearchTerm:searchTerm];

if ([self se开发者_JAVA百科archResults] == nil)
{
    NSMutableArray *array = [[NSMutableArray alloc] init];
    [self setSearchResults:array];
    [array release], array = nil;
}

[[self searchResults] removeAllObjects];

if ([[self savedSearchTerm] length] != 0)
{
    for (NSString *currentString in [self locationInfo])
    {
        if ([currentString rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound)
        {
            [[self searchResults] addObject:currentString];
        }
    }
}
}


As you stated in question that "locationInfo" is array containing 26 arrays, so, currentString in [self locationInfo] will return an array only so try to write something like below :

for (NSArray *currentArray in [self locationInfo])

{
for (NSString *currentString in currentArray)
{
    if ([currentString rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location !=  NSNotFound)
    {
        [[self searchResults] addObject:currentString];
    }
}

}

or something like this


Based on the error you're getting, it seems [self locationInfo] returns an array (NSArray) and not a string (NSString) as you're expecting.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号