1

I am making a search function and it works fine on an iphone and the iphone simulator but not the ipad simulator. When I enter my value to search it gives the error basically saying the NSRange is nil:

'NSInvalidArgumentException', reason: '* -[NSCFString rangeOfString:options:range:locale:]: nil argument'

Heres what I have.

for (int i = 0, c = names.count; i < c; ++i) {
   sFirst = [firstArray objectAtIndex:i];
   sSecond = [secondArray objectAtIndex:i];
    NSRange result = [sFirst rangeOfString:searchText options:NSCaseInsensitiveSearch];
    NSRange r = [sSecond rangeOfString:searchText options:NSCaseInsensitiveSearch];
    if (result.location != NSNotFound) {
        [searchedFirst addObject:sFirst];
        [searchedSecond addObject:sSecond];
    }    
    if (r.location != NSNotFound) {
        [searchedFirst addObject:sFirst];
        [searchedSecond addObject:sSecond];
    }    

}

Can anyone explain to me why this is happening, or is there anything I can do about this problem? Should I not worry about it since its working fine on an actual device?

SOLVED I guess since i was calling the searchText (or searchBar.text) without changing the value into a string first it returned nil. So I just declared a string in the header file.

stringValue = searchBar.text;
4

1 回答 1

2

NSRange 不能为 nil - 它不是对象,甚至不是指针。

这很可能searchText是零。

如果它在模拟器或设备上出现问题,您必须修复它,因为它总有一天失败。

于 2012-09-06T21:36:55.697 回答