Hi, I'm looking for a way to search my detailviews, so when the user starts typing inside the bar, he can then select the row and push it's particular detail view.
how can you achieve this?
Thank you
how can you achieve this?
Thank you
You don't search views. You search in the model layer that provides the data to the views. In respect of how to do this no-one can answer: it is 100% dependent on how you have written the code for the model layer and have chosen to represent the data.
I see robbie, what if my model is plist and I represent my data by using string numbers (integers), then in my code I push them using a switch statement. This is all working fine with me so far, but if I want to insert a Search Bar, I can find the text for the detailview but because the searchBar show only row # 1, it will always push the same controller.
What can I do to fix that?
( I'm learning Core Data right now and it seems to address a lot of problems like mine regarding queries (retrieving data) , fetching, search, etc.)
If it's in an Array\Dict you could use NSPredicate.
cool, thanks robbie, that must be what i'm looking because your the 2nd persons that has told me to use nspredicate.
Good day
Lol, sorry, that's Sykte
if([searchText isEqualToString:@""]searchText==nil){
That does not look like syntactically correct code.
That is because it not complete, I only pasted the part I was interested on. The complete code is on the link that Sykte provided.
if (boolValue1 boolValue2) {
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
[tableData removeAllObjects];// remove all data that belongs to previous search
if([searchText isEqualToString:@""] || searchText==nil)
{
[myTableView reloadData];
return;
}
NSInteger counter = 0;
for(NSString *name in dataSource)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSRange r = [name rangeOfString:searchText];
if(r.location != NSNotFound)
{
if(r.location== 0)//that is we are checking only the start of the names.
{
[tableData addObject:name];
}
}
counter++;
[pool release];
}
[myTableView reloadData];
}