PDA

View Full Version : Best way to search and push detailviews?




Nekbeth
Apr 1, 2011, 06:23 PM
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



robbieduncan
Apr 2, 2011, 06:06 AM
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.

Nekbeth
Apr 2, 2011, 09:13 AM
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.)

Sykte
Apr 2, 2011, 09:18 AM
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.

Nekbeth
Apr 2, 2011, 09:31 AM
If it's in an Array\Dict you could use NSPredicate.

Cool, thanks Sykte, that must be what I'm looking because your the 2nd persons that has told me to use NSPredicate.

Good day :)

Sykte
Apr 2, 2011, 09:36 AM
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, :)

Nekbeth
Apr 2, 2011, 09:59 AM
lol, :)

Lol, sorry, that's Sykte

Sykte
Apr 2, 2011, 10:10 AM
Lol, sorry, that's Sykte

It's cool, I thought it was funny. The demi god's always deserve kudo's.

Nekbeth
Apr 2, 2011, 11:17 AM
For Sykte or Robbie (or anyone else reading this thread).


Can I use this condition statement in DidSelectRowAtIndexPath ??

In this case, it's used to send a message to searchText:

if([searchText isEqualToString:@""]searchText==nil){



What I'm trying to figure out is if there is a way to push the controllers (detailviews) by their name (strings) instead of it's number (integers)?

Thank you

robbieduncan
Apr 2, 2011, 12:25 PM
That does not look like syntactically correct code.

Nekbeth
Apr 2, 2011, 12:30 PM
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 here: http://blog.webscale.co.in/?p=228

robbieduncan
Apr 2, 2011, 12:33 PM
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.

That line is not syntactically valid. It basically reads as:


if (boolValue1 boolValue2) {


This is not valid: there must be a binary operator between boolValue1 and boolValue2.

Nekbeth
Apr 2, 2011, 12:39 PM
Yes, it seems it has some syntax problems. A user correct it here:

- (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];
}