I would like to ask a question.
Now i am training in iOS with UISearchBar , TableView and Sqlite.
I have sqlite database and i want to search data from that sqlite database and then i want to show that search data in tableView.
I already select data into NSMutableArray named myArray in ViewDidLoad Event like following code.
- (void)viewDidLoad
{
[super viewDidLoad];
MyInfo *myInfo = [[MyInfo alloc] init];
myArray = [myInfo getInitialData]; // myArray is my NSMutableArray's variable name and getData From getInitialData Method.
[tableData addObjectsFromArray:myArray]; // tableData is my next NSMutableArray's variable name that i want to show search data in tableView.
}
like that.I added data from myArray into tableData.
and then i write some of code in UISearchBar’s textDidChange Events following like that.
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if([searchText isEqualToString:@""] || searchText==nil)
{
[myTableView reloadData];
return;
}
NSInteger counter = 0;
for(NSString *nameMe in myArray)
{
NSRange r = [[nameMe lowercaseString] rangeOfString:[searchText lowercaseString]];
if(r.location != NSNotFound)
{
if(r.location== 0)//that is we are checking only the start of the names.
{
[tableData addObject:nameMe];
}
}
counter++;
}
[myTableView reloadData];
}
But i can’t search data from database.There was error occurring.
I think i am wrong in my search code.
My column name is “name” that i want to search from database.
However i don’t know how to search data with UISearchBar.
If my codes are wrong,please advice me how to search data from sqlite.
I am just beginner in iOS , please help me.
Best Regards,
Here is the Link It is doing exaclty what u want to do. only u have to modify just a bit the table view in the example are filled with plist Element (correct me if i m wrong i used it long time back)
All u have to do is that fill the Array with the Values from Sqlite Database. I could have shown u that as well but i dont have my mac with me right now
Do let me know if it worked or u need any other help…!!!!
Cheeers!!!
Updated
Did u allocated ur NSMutatableArray?
Some thing like