Best way to search and push detailviews?

Discussion in 'iOS Programming' started by Nekbeth, Apr 1, 2011.

  1. macrumors member

    Nekbeth

    Joined:
    Feb 20, 2011
    Location:
    Vatican City
    #1
    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
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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.
     
  3. thread starter macrumors member

    Nekbeth

    Joined:
    Feb 20, 2011
    Location:
    Vatican City
    #3

    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.)
     
  4. macrumors regular

    Joined:
    Aug 26, 2010
    #4
    If it's in an Array\Dict you could use NSPredicate.
     
  5. Nekbeth, Apr 2, 2011
    Last edited: Apr 2, 2011

    thread starter macrumors member

    Nekbeth

    Joined:
    Feb 20, 2011
    Location:
    Vatican City
    #5
    Cool, thanks Sykte, that must be what I'm looking because your the 2nd persons that has told me to use NSPredicate.

    Good day :)
     
  6. macrumors regular

    Joined:
    Aug 26, 2010
    #6

    lol, :)
     
  7. thread starter macrumors member

    Nekbeth

    Joined:
    Feb 20, 2011
    Location:
    Vatican City
    #7
    Lol, sorry, that's Sykte
     
  8. macrumors regular

    Joined:
    Aug 26, 2010
    #8
    It's cool, I thought it was funny. The demi god's always deserve kudo's.
     
  9. thread starter macrumors member

    Nekbeth

    Joined:
    Feb 20, 2011
    Location:
    Vatican City
    #9
    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:

    Code:
     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
     
  10. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #10
    That does not look like syntactically correct code.
     
  11. Nekbeth, Apr 2, 2011
    Last edited: Apr 2, 2011

    thread starter macrumors member

    Nekbeth

    Joined:
    Feb 20, 2011
    Location:
    Vatican City
    #11
    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
     
  12. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #12
    That line is not syntactically valid. It basically reads as:

    Code:
    if (boolValue1 boolValue2) {
    
    This is not valid: there must be a binary operator between boolValue1 and boolValue2.
     
  13. thread starter macrumors member

    Nekbeth

    Joined:
    Feb 20, 2011
    Location:
    Vatican City
    #13
    Yes, it seems it has some syntax problems. A user correct it here:

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

Share This Page