2014-03-30 2 views
0

У меня PLIST в этом формате:Как получить конкретные детали в PLIST, чтобы показать в Tableview

enter image description here

Я в настоящее время показать все содержание plist.My главный вопрос это

Как я могу показать только на основе категории? У меня будет 3 категории, и я хочу, чтобы пользователь мог видеть только элемент этой категории при выборе. Посмотрите на мой первый элемент, название категории - «главное». Если пользователь выбирает основной, мне нужно показывать только основные категории.

Как это сделать?

' 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell==nil) { 
     cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
     if([[UIDevice currentDevice] userInterfaceIdiom]== UIUserInterfaceIdiomPhone) { 

      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
     } 
    } 
    cell.textLabel.text=[[self.content objectAtIndex:indexPath.row] valueForKey:@"recipeName"]; 
    // NSInteger rating; 
    //NSString *reason; 

    // rating = [[self.content objectAtIndex:indexPath.row] valueForKey:@"rating"]; 

    return cell; 


    // Configure the cell... 



' 

содержание

synthesize tableView,content=_content; 

-(NSArray*) content { 

    if(!_content){ 


     NSString *path = [[NSBundle mainBundle] pathForResource:@"recipes" ofType:@"plist" ]; 
     _content = [[NSArray alloc] initWithContentsOfFile:path]; 

    } 
    return _content; 
} 

Segue часть

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([[segue identifier] isEqualToString:@"showDetail"]) { 

     // Get destination view 
     detailViewController *destViewController = [segue destinationViewController]; 
       NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
     NSInteger tagIndex = [(UIButton *)sender tag]; 

     destViewController.recipeName =[[self.content objectAtIndex:indexPath.row] valueForKey:@"recipeName"]; 
     destViewController.recipeDetail =[[self.content objectAtIndex:indexPath.row] valueForKey:@"recipeDetail"]; 
     destViewController.recipeIngredients =[[self.content objectAtIndex:indexPath.row] valueForKey:@"recipeIngredients"]; 

это основные части

+1

Что ваш код? Что вы достигли до сих пор? – Larme

+0

oh i m добавление – user3371581

+0

@ Larme я добавил его man – user3371581

ответ

1

Я хотел бы создать новое свойство, чтобы сохранить отфильтрованный список:

@property(nonatomic, strong) NSMutableArray *filteredContent; 

Затем измените методы tableView и segue, чтобы при активном фильтре они получили доступ к массиву self.filteredContent вместо self.content.

Наконец, при замене фильтра к основнымам:

NSMutableArray *array = [NSMutableArray array]; 
for (NSDictionary *dictionary in self.content) 
    if ([[dictionary objectForKey:@"category"] isEqualToString:@"main"]) 
     [array addObject:dictionary]; 
self.filteredContent = array;   //filtered list 

[self.tableView reloadData]; //update the table view 

Надеется, что это работает для того, что вам нужно ...

+0

спасибо, что это был хороший подход – user3371581

Смежные вопросы