Sqlite 搜索栏不工作只是崩溃
这是我数据库的代码 SQLiteTutorialAppDelegate.mSqlite 搜索栏不工作只是崩溃,sqlite,search,Sqlite,Search,这是我数据库的代码 SQLiteTutorialAppDelegate.m $-(void)readAnimalsFromDatabase{ sqlite3 *database; animals = [[NSMutableArray alloc] init]; if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { const char *sqlStatement = "select * fro
$
-(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
$
(无效)搜索栏:(UISearchBar*)搜索栏文本更改:(NSString*)搜索文本{
[copyListOfItems removeAllObjects];
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
SQLiteTutorialAppDelegate *appDelegate = (SQLiteTutorialAppDelegate *)[[UIApplication sharedApplication] delegate];
for(appDelegate.animals中的NSArray*行数组)
{
for(行数组中的NSString*aName)
}
请帮助我如何在TableView中创建搜索栏搜索数据库
这为您提供了一个示例,说明搜索栏如何使用周围的内容以及如何工作
我最近也做过类似的工作,这个网站应该告诉你所有的错误,并给你一个例子说明它是如何工作的请总结你链接的内容。如果链接被破坏,我们希望答案对未来的访问者有用。
{
[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];