这可能是许多现有问题的重复,其中之一是: 此链接
或者其他我迄今为止搜索到的链接。
我正在开发一个应用程序,在其中显示人员信息,例如位置、姓名、图像、性别、电话号码等。
我通过xml获取这些数据。从解析中提取后放入NSMutableArray中,并在我的表视图中显示详细信息。
我想对这个数组中的People NAME应用搜索功能。
如何从中获取People Names?
这是我使用的代码:
用于在表视图中显示详细信息:
if (cell == nil)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCellDetail" owner:self options:nil];
id firstObject =[topLevelObjects objectAtIndex:0];
if ( [ firstObject isKindOfClass:[UITableViewCell class]] )
cell = (CustomCellDetail *)firstObject;
ParsingItem *item=[self.arrayPeoples objectAtIndex:indexPath.section];
cell.lblUserName.text=[item.mdictXMLTagsData valueForKey:@"UserName"];
cell.lblStatus.text=[item.mdictXMLTagsData valueForKey:@"StatusMessage"];
cell.lblAge.text=[item.mdictXMLTagsData valueForKey:@"Gender"];
对于获取结果,我发现只能从可变数组中搜索字符串,因此我按以下方式进行了搜索:
-(void)FetchSearcheRecordsFromArray
{
self.filteredArray = self.arrayPeoples;
NSLog(@"string :%@",strSearchingText);
NSPredicate *Predicate = [NSPredicate predicateWithFormat:@"SELF contains[c] %@",self.strSearchingText];
NSLog(@"string :%@",Predicate);
[self.filteredArray filterUsingPredicate:Predicate];
NSLog(@"Array count is : %d",[self.filteredArray count]);
if ([self.filteredArray count] <= 0 )
{
self.lblNoRecordsFound.hidden = NO;
}
else
{
self.lblNoRecordsFound.hidden = YES;
}
[self.tblViewPeople reloadData];
}
我的应用程序在第几行崩溃了:
[self.filteredArray filterUsingPredicate:Predicate];
据我所知,我的数组中没有字符串,并且有一个解析项。
我想只在人名上应用搜索,但是我不知道如何从数组中仅获取姓名。
我该怎么做?
有什么解决方法吗?
我需要完成这个任务,但不知道怎么做!!
请帮忙!
self.filteredArray = self.arrayPeoples;
的意思是arrayPeoples
数组将具有与filteredArray
相同的内容。这是您的意图吗?(如果是,为什么还要进行赋值操作呢?) - Phillip Mills