Uitableview NSInvalidArgumentException-发送到实例的选择器无法识别
我正在使用以下函数使用SearchDisplayController进行搜索Uitableview NSInvalidArgumentException-发送到实例的选择器无法识别,uitableview,ios7,uisearchdisplaycontroller,Uitableview,Ios7,Uisearchdisplaycontroller,我正在使用以下函数使用SearchDisplayController进行搜索 - (void)handleSearchForTerm:(NSString *)searchTerm{ [self.searchResults removeAllObjects]; // First clear the filtered array. FMDatabase *db = [FMDatabase databaseWithPath:[Utility getDatabasePath]]; [db ope
- (void)handleSearchForTerm:(NSString *)searchTerm{
[self.searchResults removeAllObjects]; // First clear the filtered array.
FMDatabase *db = [FMDatabase databaseWithPath:[Utility getDatabasePath]];
[db open];
FMResultSet *results = [db executeQuery: [NSString stringWithFormat:@"SELECT * FROM periods where (searchstartyear <= %@) AND (searchendyear >= %@)", searchTerm, searchTerm]];
NSMutableArray *array = [[NSMutableArray alloc] init ];
[array removeAllObjects];
while ([results next]) {
Periods *searchPeriod = [[Periods alloc] init];
searchPeriod.periodname = [results stringForColumn:@"PeriodName"];
searchPeriod.startyear = [results stringForColumn:@"StartYear"];
searchPeriod.endyear = [results stringForColumn:@"EndYear"];
searchPeriod.thumb = [results stringForColumn:@"Thumb"];
searchPeriod.childid = [results stringForColumn:@"ChildID"];
[array addObject:searchPeriod];
}
[self.searchResults addObject:array];
[db close];}
…更具体地说,当执行此行时:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"PeriodsCell";
UITableViewCell *cell = [self.mainTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
if (tableView != [[self searchDisplayController] searchResultsTableView])
{
NSMutableArray *array = [periodsdataarray objectAtIndex:indexPath.section];
NSMutableDictionary *dictionary = [array objectAtIndex:indexPath.row];
UILabel *childIDLabel = (UILabel *)[cell viewWithTag:999];
childIDLabel.text = [dictionary valueForKey:@"ChildID"];
UILabel *titleLabel = (UILabel *)[cell viewWithTag:100];
titleLabel.text = [dictionary valueForKey:@"PeriodName"];
UILabel *previewLabel = (UILabel *)[cell viewWithTag:101];
previewLabel.text = [NSString stringWithFormat:@"%@ - %@",[dictionary valueForKey:@"StartYear"],[dictionary valueForKey:@"EndYear"]];
UIImageView *imageview = (UIImageView *)[cell viewWithTag:102];
[imageview setImage:[UIImage imageNamed:[dictionary valueForKey:@"Thumb"]]];
}
else
{
Periods *periodcell = [self.searchResults objectAtIndex:indexPath.row];
cell.tag = 666;
UILabel *childIDLabel = (UILabel *)[cell viewWithTag:999];
childIDLabel.text = periodcell.childid;
UILabel *titleLabel = (UILabel *)[cell viewWithTag:100];
titleLabel.text = periodcell.periodname;
UILabel *previewLabel = (UILabel *)[cell viewWithTag:101];
previewLabel.text = [NSString stringWithFormat:@"%@ - %@",periodcell.startyear,periodcell.endyear];
UIImageView *imageview = (UIImageView *)[cell viewWithTag:102];
[imageview setImage:[UIImage imageNamed:periodcell.thumb]];
}
return cell;
}
childIDLabel.text = periodcell.childid;
我做错了什么?我在handleSearchForTerm函数中出错
我使用NSMutableArray*数组保存Periods对象的值,然后将该数组添加到searchResults数组中(期望searchResults保存Periods)。解决方案非常简单,只需将句点直接添加到我的searchResults数组和ditching数组…选择器发送到的实例的类别是什么?很抱歉,但我不确定我是否理解您的问题..您提到您遇到了一个异常。通常异常会提到类名。谢谢您的回复。这是异常消息的全文:**由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[\uu NSArrayM childid]:未识别的选择器已发送到实例0xe2b5a70',感谢您的时间。我能找到我的错误。。。在我的搜索函数中,我在搜索结果数组中添加了一个数组,而不是Periods对象,
childIDLabel.text = periodcell.childid;