Я создаю файл Plist, как показано нижеПолучить значения из файла Plist в прошивкой
Я хочу, чтобы перечислить все товары, где уровень равен 1, и я могу использовать только accessoryType = UITableViewCellAccessoryCheckmark, если уровень 1. Как я могу это сделать.
Я загрузке мой файл Plist здесь:
- (void)viewDidLoad
{
[super viewDidLoad];
countId = 0;
NSDictionary *dict=[[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Topic" ofType:@"plist"]];
self.items=[dict valueForKey:@"Items"];
self.itemsInTable=[[NSMutableArray alloc] init];
[self.itemsInTable addObjectsFromArray:self.items];
[self.menuTableView registerNib:[UINib nibWithNibName:NSStringFromClass([IndicatorTableViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([IndicatorTableViewCell class])];
UIBarButtonItem *myButton = [[UIBarButtonItem alloc]
initWithTitle:@"Done"
style:UIBarButtonItemStylePlain
target:self
action:@selector(doneSelection:)];
[self.navigationItem setRightBarButtonItem:myButton];
}
Мой код cellForRowAtIndexpath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *Title= [[self.itemsInTable objectAtIndex:indexPath.row] valueForKey:@"Name"];
return [self createCellWithTitle:Title image:[self.itemsInTable objectAtIndex:indexPath.row] indexPath:indexPath];
}
Мой код didSelectRowAtIndexPath является:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dic=[self.itemsInTable objectAtIndex:indexPath.row];
if([dic valueForKey:@"SubItems"])
{
NSArray *arr=[dic valueForKey:@"SubItems"];
BOOL isTableExpanded=NO;
for(NSDictionary *subitems in arr)
{
NSInteger index=[self.itemsInTable indexOfObjectIdenticalTo:subitems];
isTableExpanded=(index>0 && index!=NSIntegerMax);
if(isTableExpanded) break;
}
if(isTableExpanded)
{
[self CollapseRows:arr];
}
else
{
NSUInteger count=indexPath.row+1;
NSMutableArray *arrCells=[NSMutableArray array];
for(NSDictionary *dInner in arr)
{
[arrCells addObject:[NSIndexPath indexPathForRow:count inSection:0]];
[self.itemsInTable insertObject:dInner atIndex:count++];
}
[self.menuTableView insertRowsAtIndexPaths:arrCells withRowAnimation:UITableViewRowAnimationLeft];
}
}
if([[[dic valueForKey:@"SubItems"]objectAtIndex:0]objectForKey:@"level"])
{
// NSArray *arr=[dic valueForKey:@"SubItems"];
// if ([[arr objectAtIndex:0 ] intValue] == @"1")
{
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone)
{
if(countId <5)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
countId = countId + 1;
}
else
{
UIAlertView *dialog;
dialog =[[UIAlertView alloc] initWithTitle:@"Alert Message"
message:@"Select maximum 5 countries"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK",nil];
[dialog show];
// NSLog(@"Greater then 5");
}
}
else
{
if(countId>0)
{
cell.accessoryType = UITableViewCellAccessoryNone;
countId--;
}
else
{
//show alert
UIAlertView *dialog;
dialog =[[UIAlertView alloc] initWithTitle:@"Alert Message"
message:@"Select atleast 1 country"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK",nil];
[dialog show];
// NSLog(@"must choose 1");
}
}
// countId = [self.tableView indexPathsForSelectedRows].count;
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
}
Пожалуйста ответ. Я застрял здесь
Если вы хотите перечислить все элементы, на которых уровень равен 1, и вы застряли в этой точке, вы должны предоставить нам код, который загружает plist из пакета и настройки на self.itemsInTable, а также 'tableview: cellFroRowAtIndexPath:', где вы должны set 'accessoryType = UITableViewCellAccessoryCheckmark '. – FormigaNinja