Ios 如何获取plist中要在tableView中显示的特定项
我有一个这样格式的plist: 我现在展示了plist的所有内容。我的主要问题是 如何仅根据类别显示?我将有3个类别,我想让用户能够看到只是选择该类别的项目。看我的第一项,类别名称是“main”。如果用户选择主,我只需要显示主类别项目 我怎样才能做到这一点Ios 如何获取plist中要在tableView中显示的特定项,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个这样格式的plist: 我现在展示了plist的所有内容。我的主要问题是 如何仅根据类别显示?我将有3个类别,我想让用户能够看到只是选择该类别的项目。看我的第一项,类别名称是“main”。如果用户选择主,我只需要显示主类别项目 我怎样才能做到这一点 ' - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static N
'
- (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;
}
分段
- (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"];
这些是主要部分我将创建一个新属性以保留筛选列表:
@property(nonatomic, strong) NSMutableArray *filteredContent;
然后更改tableView和segue方法,以便如果有筛选器处于活动状态,它们将访问self.filteredContent数组而不是self.content
最后,将过滤器更改为main时:
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
希望它能满足您的需要…您的代码是什么?“到目前为止你取得了什么成就?”Larme我补充道,伙计