How to show filtered table view in iOS?

旧时模样 提交于 2020-01-06 08:27:13

问题


I have 2 tableViews at the moment.
One is a basic tableView which shows cells and if selected, it goes into a detailed viewController.

I created a new viewController to create a filtered page view. I populate my page view with a plist. I managed to create a filter but don't know how to proceed from here.

This is what I have:

- (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 {
        for (int i=0; i<4; i++) { 
            // i currently have 4 element is 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 is how can I show the results in a tableView?


回答1:


You create a table view and then create and assign its data source and delegate. If data in one of the table view needs to be changed when it is already displayed, the easy way to force it to update is call [tableView reloadData];



来源:https://stackoverflow.com/questions/22306047/how-to-show-filtered-table-view-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!