- (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;
}
How to do menu with submenu in tableview iOS?
-
19-10-2022 - |
Question
Hi I have to do menu with submenu in table view. Menu look like:
1. News
---|1.1
---|1.2
---|1.3
2. Weather
3. Ads
4. Cinema
Data to menu is download from server.
I have to do move cell in this menu.
Which framework used?
Solution 2
OTHER TIPS
Look at using the tableView:indentationLevelForRowAtIndexPath:
delegate method. Consider using a different table section for each menu section and set the indentation based on indexPath.row > 0
(assuming 2 levels in the menu).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow