UISearchBar - 删除行
我使用 tableview 并使用 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
结果。当我注释这一行并手动执行此操作,在搜索字段中重新键入时,它正在工作而不会崩溃!
有什么想法如何刷新结果吗?
I use a tableview and I use a UISearchBar in order to search it. I use the following code when I have to delete a row:
- (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];
}
}
}
Basically it works, but when the [self.searchDisplayController.searchBar setText:appDelegate.searchTerm]; is called, then I get the following error:
2012-01-05 15:36:05.769 iTaxFriend[9261:707] -[NSIndexPath
getCharacters:range:]: unrecognized selector sent to instance 0x3ab490
2012-01-05 15:36:05.771 iTaxFriend[9261:707] *** Terminating app due
to uncaught exception 'NSInvalidArgumentException', reason:
'-[NSIndexPath getCharacters:range:]: unrecognized selector sent to
instance 0x3ab490'
I call [self.searchDisplayController.searchBar setText:appDelegate.searchTerm];
in order to refresh the UISearch
results. When I remark this line and do it by hand, retyping on the search field, it is working without crashing!
Any ideas how to refresh the results?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论