objective c - uisearchbar in grouped section uitable -


i've pieced several tutorials create grouped table sections , i'm trying uisearchbar work. problem i'm having how search within grouped sections.

i've read similar questions post suggested can't

this code create grouped sections

#import "job.h"      // model data #import "address.h"  // model data  - (void)viewdidload {     [super viewdidload];      self.thetable.delegate = self;     self.thetable.datasource =self;      _searchbar.delegate = (id)self;      fmdbdataaccess *db = [[fmdbdataaccess alloc] init];      jobs = [[nsmutablearray alloc] init];     jobs = [db getjobs:1];      _sections = [[nsmutabledictionary alloc] init];      nsmutablearray *jobstemparray = [db getjobsasdictionary:1];      bool found;      // loop through books , create our keys     (nsdictionary *book in jobstemparray)     {         nsstring *clong = [book objectforkey:@"addraddress"];          nsstring *c = [clong substringtoindex:1];          found = no;          (nsstring *str in [_sections allkeys])         {             if ([str isequaltostring:c])             {                 found = yes;             }         }          if (!found)         {             [_sections setvalue:[[nsmutablearray alloc] init] forkey:c];         }      }      // loop again , sort books respective keys     (nsdictionary *book in jobstemparray)     {         [[_sections objectforkey:[[book objectforkey:@"addraddress"] substringtoindex:1]] addobject:book];     }      // sort each section array     (nsstring *key in [_sections allkeys])     {         [[_sections objectforkey:key] sortusingdescriptors:[nsarray arraywithobject:[nssortdescriptor sortdescriptorwithkey:@"addraddress" ascending:yes]]];     }  } 

and code searches

-(void)searchbar:(uisearchbar*)searchbar textdidchange:(nsstring*)text {     if(text.length == 0)     {         _isfiltered = false;     }     else     {         _isfiltered = true;         _filteredjobs = [[nsmutablearray alloc] init];          //for (job* book in jobs)         //for (job* book in [_sections allkeys])         //for (nsstring *food in [_sections allkeys])         (nsdictionary* book in [_sections allkeys])         {             nsstring *addrstr = [book objectforkey:@"addraddress"];             nsstring *poststr = [book objectforkey:@"addrpostcode"];              //nsrange namerange = [book.jobaddress rangeofstring:text options:nscaseinsensitivesearch];             nsrange namerange = [addrstr rangeofstring:text options:nscaseinsensitivesearch];              //nsrange descriptionrange = [book.jobpostcode rangeofstring:text options:nscaseinsensitivesearch];             nsrange descriptionrange = [poststr rangeofstring:text options:nscaseinsensitivesearch];              if(namerange.location != nsnotfound || descriptionrange.location != nsnotfound)             {                 [_filteredjobs addobject:book];             }         }     }      [self.thetable reloaddata]; } 

i've got far realising need change for (job* food in jobs) for (nsdictionary* book in [_sections allkeys]) i'm stuck how search within [_sections allkeys]

specifically line

nsrange namerange = [addrstr rangeofstring:text options:nscaseinsensitivesearch]; 

which crashes

-[__nscfstring objectforkey:]: unrecognized selector sent instance 0x692e200

*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nscfstring objectforkey:]: unrecognized selector sent instance 0x692e200':

any ideas? ps treat me noob, i'll need code explanation - i'm still learning obj-c

check link.it shows uisearchbar grouped section tableview.its simple tutorial..hope useful you


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -