ate问题与numberOfRowsInSection方法一起使

ate问题与numberOfRowsInSection方法一起使

本文介绍了NSPredicate问题与numberOfRowsInSection方法一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现对UITableView的搜索.首先,我使用-(void)viewDidLoad方法填充数据库中的历史记录数组.

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;

然后我尝试实现方法

- (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;

}

在视图控制器中,UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate

And in the View Controller UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate

tableCells中的字符串以类似1789-1798的日期开头.当我尝试搜索信息时,搜索方法仅适用于第一个数字……例如,我有一个单元格,其信息以数字5开头.当我键入UISearchBar数字5时,该方法返回的记录以1.当我输入两个数字时,方法将返回无结果".问题出在哪里,我哪里出问题了?

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?

推荐答案

好吧,我自己解决了这个问题.我迷上了cellForRowAtIndexPath方法.

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

这篇关于NSPredicate问题与numberOfRowsInSection方法一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 03:50