嗨,我必须在表视图中的子菜单做菜单。菜单看起来像:
1. News ---|1.1 ---|1.2 ---|1.3 2. Weather 3. Ads 4. Cinema
如何使用tableview iOS中的子菜单做菜单?
数据到菜单是从服务器下载。
我必须在此菜单中移动单元格。
使用哪个框架?
嗨,我必须在表视图中的子菜单做菜单。菜单看起来像:
1. News ---|1.1 ---|1.2 ---|1.3 2. Weather 3. Ads 4. Cinema
如何使用tableview iOS中的子菜单做菜单?
数据到菜单是从服务器下载。
我必须在此菜单中移动单元格。
使用哪个框架?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.menus.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 55;;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 70;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[self.menu objectAtIndex:section] objectForKey:@"submenus"];
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 70)];
headerView.backgroundcolor = [UIColor clearcolor];
UILabel *menuTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, tableView.frame.size.width - 5, 60)];
menuTitleLabel.backgroundColor = [UIColor clearColor];
menuTitleLabel.textColor = [UIColor colorWithRed:68.0/255.0 green:68.0/255.0 blue:68.0/255.0 alpha:1.0];;
menuTitleLabel.text = [[[self.menus objectAtIndex:section] objectForKey:@"title"] uppercaseString];
menuTitleLabel.font = [UIFont fontWithName:@"Roboto-Bold" size:16.0];
[menuTitleLabel setAdjustsFontSizeToFitWidth:YES];
[headerView addSubview:menuTitleLabel];
return headerView;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *submenuArray = [[self.menus objectAtIndex:indexPath.section] objectForKey:@"submenus"];;
static NSString *CellIdentifier = @"MenuCell";
MenuCell *cell = (MenuCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MenuCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.backgroundColor = [UIColor clearColor];
}
cell.title.backgroundColor = [UIColor clearColor];
cell.title.font = [UIFont fontWithName:@"Roboto-Bold" size:16.0];
cell.title.text = [subMenuArray objectAtIndex:indexPath.row]objectForKey:@"title"];
cell.title.textColor = [UIColor colorWithRed:68.0/255.0 green:68.0/255.0 blue:68.0/255.0 alpha:1.0];
return cell;
}
创建一个自定义的UITableViewCell MenuCell,从服务器加载菜单menus数组,重载tablew.The视图头将包含您的所需的数据如News,Weather等,并在行方法的单元格中分别准备子菜单 – Nassif
看看使用tableView:indentationLevelForRowAtIndexPath:
委托方法。考虑为每个菜单部分使用不同的表格部分,并根据indexPath.row > 0
(假设菜单中有2个层次)设置缩进。
请尝试答案,让我知道 – Nassif
searchableWordsList和菜单是nsdictionary? – wysio90
我的错误,我编辑了答案。什么是你的菜单格式 – Nassif