我工作的自定義聯繫人,我目前使用此代碼搜索自定義對象搜索自定義對象
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