Iphone 如何将搜索栏添加到从plist填充的表视图中
我尝试过使用几个不同的搜索栏示例,但添加搜索栏却没有任何运气。如果能提供任何帮助,我将不胜感激。下面是代码,我使用的是搜索栏控制器示例Iphone 如何将搜索栏添加到从plist填充的表视图中,iphone,xcode,search,plist,Iphone,Xcode,Search,Plist,我尝试过使用几个不同的搜索栏示例,但添加搜索栏却没有任何运气。如果能提供任何帮助,我将不胜感激。下面是代码,我使用的是搜索栏控制器示例 if(CurrentLevel == 0) { //Initialize our table data source NSArray *tempDict = [[NSArray alloc] init]; self.tableDataSource = tempDict;
if(CurrentLevel == 0) {
//Initialize our table data source
NSArray *tempDict = [[NSArray alloc] init];
self.tableDataSource = tempDict;
[tempDict release];
Midwest_DigestiveAppDelegate *AppDelegate = (Midwest_DigestiveAppDelegate *)[[UIApplication sharedApplication] delegate];
self.tableDataSource = [AppDelegate.data valueForKey:@"Rows"];
//Initialize the array.
NSMutableArray *listOfItems = [[NSMutableArray alloc] init];
[listOfItems addObjectsFromArray:tableDataSource];
//Initialize the copy array.
NSMutableArray *copyListOfItems = [[NSMutableArray alloc] init];
//Add the search bar
self.tableView.tableHeaderView = searchBar;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
searching = NO;
letUserSelectRow = YES;
}
else
self.navigationItem.title = CurrentTitle;
//Initialize the array.
NSMutableArray *listOfItems = [[NSMutableArray alloc] initW];
[listOfItems addObjectsFromArray:tableDataSource];
//Initialize the copy array.
NSMutableArray *copyListOfItems = [[NSMutableArray alloc] init];
//Add the search bar
self.tableView.tableHeaderView = searchBar;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
searching = NO;
letUserSelectRow = YES;
}
- (void) searchTableView {
NSString *searchText = searchBar.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (NSDictionary *dictionary in listOfItems)
{
NSArray *array = [dictionary objectForKey:@"Title"];
[searchArray addObjectsFromArray:array];
}
for (NSString *sTemp in searchArray)
{
NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[copyListOfItems addObject:sTemp];
}
[searchArray release];
searchArray = nil;
}
你的问题是什么?你觉得这个应用程序做了什么(或没有做什么)是不对的?我有一个plist显示在uitableview中。该视图从两个选项开始:程序和教育。它从plist获取此列表。选择后,它将带您进入程序或信息列表。我想在每一级添加一个搜索栏,这样随着列表的增长,它仍然是可搜索的。a)这不是编程问题,这是一个功能要求。b) 您尝试过哪些不起作用的方法?您收到了什么错误消息?如果您正在寻找插入式代码来解决您的问题,那么就不是这样了。另一方面,如果你说,“我尝试了x、y和z,但我得到了错误foo”,或“我在我的表中没有得到结果”,或“CellForRowatineXpath中的应用程序崩溃…”,那么也许我们可以帮助你摆脱困境。干杯。我使用self.tableDataSource成功地从plist加载了表。我的覆盖效果很好,但当我点击搜索栏开始键入时,我的表格就完全消失了。这意味着我的listOfItems和copyListOfItems没有被填充。我没有收到错误消息。我的plist由多个级别组成,我希望能够在每个级别上进行搜索。我缩短了代码以向您显示我的viewDidLoad和searchtableView。(在您发布的代码中,第5行无效,因为您随后在第10行覆盖了self.tableViewDataSource。但这不是问题。)我建议您将NSLog语句放在cellForRowAtIndexPath:和numberOfRowsInSection:方法中,然后在调试器中逐步执行它们。这些将填充表格单元格。确保从您认为是的阵列中获取数据。