UISearchBar - удалить строку - PullRequest
       10

UISearchBar - удалить строку

1 голос
/ 05 января 2012

Я использую таблицу и использую UISearchBar для ее поиска. Я использую следующий код, когда мне нужно удалить строку:

- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath {

    if(editingStyle == UITableViewCellEditingStyleDelete) {

//Get the object to delete from the array.

    Coffee *coffeeObj = nil;

    if (tv == self.searchDisplayController.searchResultsTableView)
    {
        coffeeObj = [appDelegate.coffeeArrayFiltered objectAtIndex:indexPath.row];
    }
    else
    {
        coffeeObj = [appDelegate.coffeeArray objectAtIndex:indexPath.row];
    }


    appDelegate.countRowNumber -= 1;
    NSString *txtmessage2an = [NSString stringWithFormat:@"%@", coffeeObj.price];
    float priceFn = [txtmessage2an floatValue];
    NSString *txtmessage3a = [NSString stringWithFormat:@"%0.2f", priceFn];
    float stringDouble1 = [txtmessage3a floatValue];
    float stringDouble2 = appDelegate.countPriceNumber;
    float stringDoubleSum = stringDouble2 - stringDouble1;
    appDelegate.countPriceNumber = stringDoubleSum;
    [appDelegate removeCoffee:coffeeObj];

    //Delete the object from the table.

            [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [self.tableView reloadData];

    if([appDelegate.searchTerm isEqualToString:@"!"]){
        NSLog(@"Not in search...");
    }
    else
    {
        NSLog(appDelegate.searchTerm);
        [self.searchDisplayController.searchBar setText:appDelegate.searchTerm];
    }
}
}

В основном это работает, но когда [self.searchDisplayController.searchBar setText: appDelegate.searchTerm]; вызывается, то я получаю следующую ошибку:

2012-01-05 15: 36: 05.769 iTaxFriend [9261: 707] - [NSIndexPath getCharacters: range:]: нераспознанный селектор отправлен на экземпляр 0x3ab490 2012-01-05 15: 36: 05.771 iTaxFriend [9261: 707] *** Завершение работы приложения чтобы исключить исключение 'NSInvalidArgumentException', причина: '- [NSIndexPath getCharacters: range:]: нераспознанный селектор отправлен экземпляр 0x3ab490 '

Я звоню [self.searchDisplayController.searchBar setText:appDelegate.searchTerm];, чтобы обновить результаты UISearch. Когда я отмечаю эту строку и делаю это вручную, перепечатывая поле поиска, она работает без сбоев!

Есть идеи, как обновить результаты?

...