-1

NSMutableArray で何らかの検索を行っていますが、SIGABRT が頻繁に発生します。私はobjective-cが初めてなので、ここで重要なことを見逃したかどうかわかりません...

-(IBAction)findButtonPushed:(id)sender
{
    Data *stuff = [Data getInstance];
    [stuff.results removeAllObjects];
    NSMutableArray *tempResults = [[NSMutableArray alloc] init];


    for (Company *company in stuff.companies) {
        if ([company.Description rangeOfString:[sbWhat text] options:NSCaseInsensitiveSearch].location != NSNotFound
            || [company.Name rangeOfString:[sbWhat text] options:NSCaseInsensitiveSearch].location != NSNotFound
            || [company.Url rangeOfString:[sbWhat text] options:NSCaseInsensitiveSearch].location != NSNotFound
            || [company.FirstName rangeOfString:[sbWhat text] options:NSCaseInsensitiveSearch].location != NSNotFound
            || [company.LastName rangeOfString:[sbWhat text] options:NSCaseInsensitiveSearch].location != NSNotFound
            || [company.Keywords rangeOfString:[sbWhat text] options:NSCaseInsensitiveSearch].location != NSNotFound) {
            [tempResults addObject:company];
        }
    }


    if (![[sbWhere text] isEqualToString:@""]) {
        for (Company *company in tempResults) {
            if ([company.Street rangeOfString:[sbWhere text] options:NSCaseInsensitiveSearch].location != NSNotFound
                || [company.City rangeOfString:[sbWhere text] options:NSCaseInsensitiveSearch].location != NSNotFound
                || [company.ZipCode rangeOfString:[sbWhere text] options:NSCaseInsensitiveSearch].location != NSNotFound
                || [company.State rangeOfString:[sbWhere text] options:NSCaseInsensitiveSearch].location != NSNotFound
                || [company.AddressPt1 rangeOfString:[sbWhere text] options:NSCaseInsensitiveSearch].location != NSNotFound
                || [company.AddressPt2 rangeOfString:[sbWhere text] options:NSCaseInsensitiveSearch].location != NSNotFound
                || [company.Country rangeOfString:[sbWhere text] options:NSCaseInsensitiveSearch].location != NSNotFound) {
                [stuff.results addObject:company];
            }
        }
    }
    else{
        stuff.results = tempResults;
    }


    [self performSegueWithIdentifier:@"ShowResults" sender:self];
}

ところで、sbWhere と sbUISearchBars とは

これら 2 つの if ステートメントで SIGABRT を取得しています。json文字列を解析して得た会社。

4

1 に答える 1

3

テキストをチェックしませんnil。渡すnilrangeOfString:、例外がスローされます。また、同じメソッドを複数回呼び出すのではなく、文字列を保存する必要があります。

NSString *what = [sbWhat text];
//Make sure what is not nil or empty
if([what length])
    for (Company *company in stuff.companies) {
        ...


NSString *where = [sbWhere text];
//Make sure where is not nil or empty
if ([where length]) {
    for (Company *company in tempResults) {
        ...

コンソールは、今後投稿に含める必要があるテキストを逆流させた可能性もあります. 例えば:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString rangeOfString:options:range:locale:]: nil argument' *** First throw call stack: (0x149c022 0x162dcd6 0x1444a48 0x14449b9 0x9360f6 0x96e17c 0x2a5f 0x2825 0x1) terminate called throwing an exception

于 2012-06-28T19:26:01.567 に答える