我工作的自定义联系人,我目前使用此代码搜索自定义对象搜索自定义对象
filteredTableData = [[NSMutableArray alloc] init];
for (int i=0; i<contactSectionTitles.count; i++)
{
NSString *sectionTitle = [contactSectionTitles objectAtIndex:i];
NSArray *sectionmContacts = [mContacts objectForKey:sectionTitle];
for (CS_ContactDTO *theDto in sectionmContacts) {
NSRange nameRange = [theDto.mFirstName rangeOfString:text options:NSForcedOrderingSearch];
NSRange descriptionRange = [[theDto.mFirstName description] rangeOfString:text options:NSForcedOrderingSearch];
if(nameRange.location != NSNotFound || descriptionRange.location != NSNotFound)
{
if (![filteredTableData containsObject:theDto])//Search DTO
{
[filteredTableData addObject:theDto];
}
}
}
}
注意 “theDTO”是我的自定义类
它值FirstName,LastName,PhoneNumber。
代码给我造成像,
对于“A” - >“阿伦”,“印度”,“库玛”
我的要求是要搜索
“A”只提供“阿朗”(开始字母匹配),而不是其他结果。
听不懂你的要求,你要搜索'name'或'description'与开始搜索字符串? – bhargavg 2014-09-04 15:34:38
我需要搜索名字。 – 2014-09-04 15:36:30