这是我的数据库的代码 SQLiteTutorialAppDelegate.m
$
.-(void)readAnimalsFromDatabase {
sqlite3 *database;
animals = [[NSMutableArray alloc] init];
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement = "select * from animals";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSString *aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSString *aImageUrl = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
// Create a new animal object with the data from the database
Animal *animal = [[Animal alloc] initWithName:aName description:aDescription url:aImageUrl];
// Add the animal object to the animals Array
[animals addObject:animal];
[animal release];
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
和RootViewController.m
$
.-(void)searchBar:(UISearchBar *)SearchBar textDidChange:(NSString *)searchText {
[copyListOfItems removeAllObjects];
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
SQLiteTutorialAppDelegate *appDelegate = (SQLiteTutorialAppDelegate *)[[UIApplication sharedApplication] delegate];
for(appAlegate.animals中的NSArray * rowArray) { for(NSAtring * aName in rowArray)
{
[searchArray addObject:rowArray]; // HERE CRASH
}
}
for (NSString *sTemp in searchArray)
{
NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length == 0)
[copyListOfItems addObject:sTemp];
}
[self.tableView reloadData];
}
请帮我看看如何在TableView中创建搜索栏搜索数据库
答案 0 :(得分:0)
http://www.appcoda.com/search-bar-tutorial-ios7/
这为您提供了一个示例,说明搜索栏如何使用它周围的内容及其工作原理
我最近在类似的东西上工作,这个网站应该告诉你一切都错了,并给你一个如何工作的例子