2012-05-09 32 views
-2

可能重复:
Search bar in Xcode IPhoneUISearch在一个UITableView的Xcode问题

我的iPhone应用程序工作的UISearchBar。我正在寻找一个简单的应用程序来过滤联系人列表。任何人都可以在这个问题上引导我。我在屏幕顶部有一个搜索栏。我需要一个代码来实现联系人列表中的搜索。

请在这个问题上指导我。

感谢

+0

你已经问过这个问题的某个时候回来 - http://stackoverflow.com/questions/10510131/search-bar-in-xcode-iphone – rishi

回答

0
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope 
{ 
    // Update the filtered array based on the search text and scope. 
    [self.filteredListContent removeAllObjects]; // First clear the filtered array. 


    //mode==1 means search mode. mode==0 means normal mode. 
    if (![searchText isEqualToString:@""]) { 
     mode=1; 
    } 

    for (id arrayObject in listContent) 
    { 
     NSString *objectInfo=[arrayObject getDescription]; 
     NSRange result=[objectInfo rangeOfString:searchText options:NSCaseInsensitiveSearch]; 
     if (result.location >= 0 && result.location<=[objectInfo length]) 
     { 
      [self.filteredListContent addObject:arrayObject]; 
     } 
    } 
}