ios - How to create table view controller from filtered arrays in Xcode? -


i have 2 tableviews @ moment. 1 basic shows each cells , if selected navigates detail view controller.

i created new viewcontroller create filtered page view. populate page view plist. managed create filter don't know how proceed here.

this code:

- (ibaction)ingredientsaddbutton:(uibutton *)sender  {     int j=0;     onemsiz.text=ingredienttextfield.text;     ingredienttext=onemsiz.text;     nslog(ingredienttext);     nsstring *path = [[nsbundle mainbundle] pathforresource:@"recipes" oftype:@"plist"];     nsarray *arrayofplist = [[nsarray alloc] initwithcontentsoffile:path];     if (arrayofplist==null) {      }else {         (int i=0; i<4; i++) {              // have 4 element plist.             nsstring *strcurrentrecipeingredients = [[arrayofplist objectatindex:i] objectforkey:@"recipeingredients"];             nsstring *strcurrentrecipename = [[arrayofplist objectatindex:i] objectforkey:@"recipename"];             //nslog(@"%d. loop \n", i+1);             if([strcurrentrecipeingredients rangeofstring:(@"%@",ingredienttext)].location!=nsnotfound)             {                 nslog(@"%@ contains %@ ",strcurrentrecipename, ingredienttext);                 nslog(ingredienttext);                 nslog(strcurrentrecipeingredients);                 j++;             }else {                 nslog(@"not found");                 nslog(ingredienttext);                 nslog(strcurrentrecipeingredients);             }             if (ingredienttext==null) {                 nslog(@"empty input");             }else {              }         }     }     nslog(@"%d",j); } 

my first problem how can show results in table view? can give screenshots if want.

you can add bool ivar tell when need show filtered array , new array show filtered data:

bool isshowfiltereddata; nsarray *filtereddata; 

in init or viewdidload initialize bool false (you don't want show data);

isshowfiltereddata = no; 

you have change datasource/delegate method use right data:

- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return isshowfiltereddata ? isshowfiltereddata.count : mydataarray.count; }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     //configure cell, etc..     //your code      if (isshowfiltereddata)      {          // show filtered data          id obj = filtereddata[indexpath.row];          // result     }     else     {         // show data     } } 

now when want show filtered data change ivar true, initialise filtereddata array , fill in data want show , call reloaddata:

isshowfiltereddata = yes; filtereddata = [[nsarray alloc] initwithobjects:.....]; [self.tableview reloaddata]; 

but if want show data do:

isshowfiltereddata = no; [self.tableview reloaddata]; 

this 1 of solution can use.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -