NSPredicate issue using with numberOfRowsInSection method

牧云@^-^@ 提交于 2019-12-25 09:30:01

问题


I am trying to implement search for UITableView. First I fill my array of historical periods from DB in - (void)viewDidLoad method.

self.periodsArr=[dbAccsess getPeriods:subCountryID];
self.searchBar = [[[UISearchBar alloc]initWithFrame:
                   CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)] autorelease];
searchBar.delegate=self;
self.tableView.tableHeaderView = self.searchBar;
searchBar.keyboardType=UIKeyboardTypeNumberPad;
self.searchController = [[[UISearchDisplayController alloc]
                          initWithSearchBar:self.searchBar contentsController:self] autorelease];
self.searchController.searchResultsDataSource = self; 
self.searchController.searchResultsDelegate = self;

Then I try to implement method

- (NSInteger)tableView:(UITableView *)utableView numberOfRowsInSection:(NSInteger)section
{
if(utableView==self.tableView)
{
    return [self.periodsArr count];
}
NSPredicate *predicate = [NSPredicate predicateWithFormat:
                          @"period beginswith[c] %@", self.searchBar.text];
filteredItems=[[NSMutableArray alloc]init];
self.filteredItems=[self.periodsArr filteredArrayUsingPredicate:predicate];
return filteredItems.count;

}

And in the View Controller UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate

The strings in the tableCells are beginning with dates like 1789-1798. When I am trying to search the information, the search methods works only for first number.... for example I have a cell with information beginning with number 5. When I type in UISearchBar digit 5, the method returns me the record beginning with 1. When I type two numbers, method returns me 'no results'. Where's the problem and where I went wrong?


回答1:


Well, I solved this issue by myself. I was screwed up in cellForRowAtIndexPath meth.



来源:https://stackoverflow.com/questions/8733065/nspredicate-issue-using-with-numberofrowsinsection-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!