arrays - iPhone search results showing incorrect descriptions after touch -


i having trouble search. displays search results correctly, when click on item in results, opens item c's description.

#import "rootviewcontroller.h"  #import "fsdappdelegate.h"  #import "detailviewcontroller.h"  @implementation rootviewcontroller  #pragma mark - #pragma mark synthesizers  @synthesize maintableview; @synthesize contentslist; @synthesize descarray; @synthesize bannerimages; @synthesize childcontroller; @synthesize searchresults; @synthesize savedsearchterm;   #pragma mark - #pragma mark view methods  - (void)viewdidload {    nslog(@">>> entering %s <<<", __pretty_function__);       nsstring *filepath = [[nsbundle mainbundle] pathforresource:@"descriptions" oftype:@"plist"];      nsarray *desc = [[nsarray alloc] initwithcontentsoffile:filepath];     self.descarray = desc;     [desc release];      uiimage *texas = [uiimage imagenamed:@"1andtexas.jpg"];     uiimage *cali = [uiimage imagenamed:@"2andcalifornia.jpg"];     uiimage *ny = [uiimage imagenamed:@"3andnewyork.jpg"];     uiimage *tmark = [uiimage imagenamed:@"1tmark.jpg"];     uiimage *walkie = [uiimage imagenamed:@"walkietalkie.jpg"];     uiimage *onekh = [uiimage imagenamed:@"tracingpaper.jpg"];     uiimage *onetwonine = [uiimage imagenamed:@"diffusion.jpg"];     uiimage *greycard = [uiimage imagenamed:@"greycard.jpg"];     uiimage *oneeighty = [uiimage imagenamed:@"oneeighty.jpg"];     uiimage *two = [uiimage imagenamed:@"two.jpg"];     uiimage *twofourteen = [uiimage imagenamed:@"diffusion.jpg"];     uiimage *twofifteen = [uiimage imagenamed:@"diffusion.jpg"];     uiimage *twosixteen = [uiimage imagenamed:@"diffusion.jpg"];     uiimage *twotwenty = [uiimage imagenamed:@"diffusion.jpg"];     uiimage *twotwentynine = [uiimage imagenamed:@"diffusion.jpg"];     uiimage *twofifty = [uiimage imagenamed:@"diffusion.jpg"];     uiimage *twofiftyone = [uiimage imagenamed:@"diffusion.jpg"];     uiimage *twofiftytwo = [uiimage imagenamed:@"diffusion.jpg"];     uiimage *twofiftythree = [uiimage imagenamed:@"diffusion.jpg"];     uiimage *twofiftyfour = [uiimage imagenamed:@"diffusion.jpg"];     uiimage *twofiftyfive = [uiimage imagenamed:@"diffusion.jpg"];     uiimage *twofiftysix = [uiimage imagenamed:@"diffusion.jpg"];     uiimage *twofiftyseven = [uiimage imagenamed:@"diffusion.jpg"];     uiimage *twofiftyeight = [uiimage imagenamed:@"diffusion.jpg"];     uiimage *thirtytwohk = [uiimage imagenamed:@"3200k.jpg"];        nsarray *banners = [[nsarray alloc] initwithobjects:                         texas,                         cali,                         ny,                         tmark,                         walkie,                         onekh,                         onetwonine,                         greycard,                         oneeighty,                         two,                         twofourteen,                         twofifteen,                         twosixteen,                         twotwenty,                         twotwentynine,                         twofifty,                         twofiftyone,                         twofiftytwo,                         twofiftythree,                         twofiftyfour,                         twofiftyfive,                         twofiftysix,                         twofiftyseven,                         twofiftyeight,                         thirtytwohk,                         nil];      self.bannerimages = banners;      [banners release];       [super viewdidload];        nsmutablearray *array = [[nsmutablearray alloc] initwithobjects:                              @"#1 or number one",                              @"#2 or number two",                              @"#3 or number three",                              @"1 or one",                              @"10-100,10-1,10-200,10-2,10-4 , 20",                              @"1000h paper",                              @"129 or heavy frost",                              @"18% gray or grey card",                              @"180 degree rule",                              @"2 or two",                              @"214 or full tough spun",                              @"215 or half tough spun",                              @"216 or full white diffusion",                              @"220 or white frost",                              @"229 or quarter tough spun",                              @"250 or half white diffusion",                              @"251 or quarter white diffusion",                              @"252 or eighth white diffusion",                              @"253 or full hampshire",                              @"254 or new hampshire",                              @"255 or hollywood frost",                              @"256 or half hampshire frost",                              @"257 or quarter hampshire frost",                              @"258 or eighth hampshire frost",                              @"3200k or tungsten",                              nil];     [self setcontentslist:array];     [array release], array = nil;      if ([self savedsearchterm])     {         [[[self searchdisplaycontroller] searchbar] settext:[self savedsearchterm]];     }      nslog(@"<<< leaving %s >>>", __pretty_function__); }  - (void)viewwillappear:(bool)animated {     nslog(@">>> entering %s <<<", __pretty_function__);      [super viewwillappear:animated];      [[self maintableview] reloaddata];      nslog(@"<<< leaving %s >>>", __pretty_function__); }  #pragma mark - #pragma mark table view datasource methods  - (nsarray *)sectionindextitlesfortableview:(uitableview *)tableview {      nsmutablearray *tobereturned = [[nsmutablearray alloc]init];     for(char c = 'a'; c <= 'z'; c++) [tobereturned addobject:[nsstring stringwithformat:@"%c",c]];     return tobereturned; }  -(nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     nslog(@">>> entering %s <<<", __pretty_function__);      nsinteger rows;      if (tableview == [[self searchdisplaycontroller] searchresultstableview])         rows = [[self searchresults] count];     else         rows = [[self contentslist] count];       nslog(@"rows is: %d", rows);     nslog(@"<<< leaving %s >>>", __pretty_function__);      return rows;      }  -(uitableviewcell *) tableview:(uitableview *)tableview          cellforrowatindexpath:(nsindexpath *)indexpath {      nslog(@">>> entering %s <<<", __pretty_function__);      nsinteger row = [indexpath row];     nsstring *contentforthisrow = nil;      if (tableview == [[self searchdisplaycontroller] searchresultstableview])         contentforthisrow = [[self searchresults] objectatindex:row];     else         contentforthisrow = [[self contentslist] objectatindex:row];      static nsstring *cellidentifier = @"cellidentifier";      uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];     if (cell == nil)     {          cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease];     }      [[cell textlabel] settext:contentforthisrow];      //cell.textlabel.text = [contentslist objectatindex:indexpath.row];      cell.accessorytype = uitableviewcellaccessorydisclosureindicator;      nslog(@"<<< leaving %s >>>", __pretty_function__);      return cell; }  #pragma mark - #pragma mark table view delegate methods  -(cgfloat) tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {     return 50; }  -(nsstring *) tableview:(uitableview *)tableview titleforfooterinsection:(nsinteger)section {     return @"film set decipher"; }  -(void) tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     nslog(@">>> entering %s <<<", __pretty_function__);      fsdappdelegate *delegate = (fsdappdelegate *)[[uiapplication sharedapplication] delegate];     detailviewcontroller *detailvc = [[detailviewcontroller alloc] initwithnibname:@"detailviewcontroller" bundle:nil];     detailvc.banner = [bannerimages objectatindex:indexpath.row];     detailvc.description = [descarray objectatindex:indexpath.row];     detailvc.title = [contentslist objectatindex:indexpath.row];     self.childcontroller = detailvc;     [delegate.navigationcontroller pushviewcontroller:childcontroller animated:yes];       [detailvc release];      [tableview deselectrowatindexpath:indexpath animated:yes];      nslog(@"<<< leaving %s >>>", __pretty_function__); }  #pragma mark - #pragma mark uisearchdisplaycontroller delegate methods  - (bool)searchdisplaycontroller:(uisearchdisplaycontroller *)controller  shouldreloadtableforsearchstring:(nsstring *)searchstring {     nslog(@">>> entering %s <<<", __pretty_function__);      [self handlesearchforterm:searchstring];      nslog(@"<<< leaving %s >>>", __pretty_function__);     return yes; }  - (void)searchdisplaycontrollerwillendsearch:(uisearchdisplaycontroller *)controller {     nslog(@">>> entering %s <<<", __pretty_function__);      [self setsavedsearchterm:nil];      [[self maintableview] reloaddata];      nslog(@"<<< leaving %s >>>", __pretty_function__); } #pragma mark - #pragma mark memory management  - (void)didreceivememorywarning {     nslog(@"memory warning!");     [super didreceivememorywarning]; } - (void)dealloc {     nslog(@">>> entering %s <<<", __pretty_function__);      [maintableview release]; maintableview = nil;     [contentslist release]; contentslist = nil;     [descarray release]; descarray = nil;     [bannerimages release]; bannerimages = nil;     [childcontroller release]; childcontroller = nil;     [searchresults release], searchresults = nil;     [savedsearchterm release], savedsearchterm = nil;      [super dealloc];      nslog(@"<<< leaving %s >>>", __pretty_function__); }  - (void)viewdidunload {     nslog(@">>> entering %s <<<", __pretty_function__);      self.maintableview = nil;     self.contentslist = nil;     self.descarray = nil;     self.bannerimages = nil;     self.childcontroller = nil;      [super viewdidunload];      [self setsavedsearchterm:[[[self searchdisplaycontroller] searchbar] text]];      [self setsearchresults:nil];      nslog(@"<<< leaving %s >>>", __pretty_function__);  }  - (void)handlesearchforterm:(nsstring *)searchterm {     nslog(@">>> entering %s <<<", __pretty_function__);      [self setsavedsearchterm:searchterm];      if ([self searchresults] == nil)     {         nsmutablearray *array = [[nsmutablearray alloc] init];         [self setsearchresults:array];         [array release], array = nil;     }      [[self searchresults] removeallobjects];      if ([[self savedsearchterm] length] != 0)     {         (nsstring *currentstring in [self contentslist])         {             if ([currentstring rangeofstring:searchterm options:nscaseinsensitivesearch].location != nsnotfound)             {                 [[self searchresults] addobject:currentstring];             }         }     }      nslog(@"<<< leaving %s >>>", __pretty_function__); }  @end 

i not sure, pulling description plist. seems detailvc.title = [contentslist objectatindex:indexpath.row]; needs able use descarray? ideas?

thanks in advance!

u should use 2 diff arrays in such conditions..

ur code should follows,

if(searching==yes)  {  //retrieve values source array  }  else  {  //retrieve values filtered array  } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -