我正在设计一个 uitableview,该部分中有多个部分和行,我为此具有展开和折叠功能。现在,当行展开时,我在行和部分之间留出了空间,如下图所示。
这是我用于展开和折叠部分的代码。对于部分,我使用标题视图。
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return menuarray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//return menuarray.count;
if ([arrSelectedSectionIndex containsObject:[NSNumber numberWithInteger:section]])
{
NSArray *arr=[menuarray[section] valueForKey:@"menu"];
return arr.count;
}else{
return 0;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MenudetailsTblCell";
menudetailscell = ( MenudetailsTblCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// [self.tblview registerNib:[UINib nibWithNibName:@"MenudetailsTblCell" bundle:nil]
//forCellReuseIdentifier:@"MenudetailsTblCell"];
if (menudetailscell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MenudetailsTblCell" owner:self options:nil];
menudetailscell = [nib objectAtIndex:0];
}
if (menudetailscell == nil)
{
menudetailscell = [[MenudetailsTblCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
menudetailscell.contentView.layer.cornerRadius = 5;
menudetailscell.contentView.layer.masksToBounds = YES;
NSArray *arr=[menuarray[indexPath.section] valueForKey:@"menu"];
menudetailscell.typelbl.text=[[arr objectAtIndex:indexPath.row]valueForKey:@"name"];
menudetailscell.describtionlbl.text=[[arr objectAtIndex:indexPath.row]valueForKey:@"description"];
NSString *cost=[NSString stringWithFormat:@"%@%@",[[arr objectAtIndex:indexPath.row]valueForKey:@"price"],@".00"];
NSString *imgid=[NSString stringWithFormat:@"%@",[[arr objectAtIndex:indexPath.row]valueForKey:@"idmenus"]];
NSString *tax=[NSString stringWithFormat:@"%@",[[arr objectAtIndex:indexPath.row]valueForKey:@"tax"]];
if ([tax isEqualToString:@"tax"]) {
menudetailscell.taxlbl.text=@"(*Inclusive all taxes)";
}else{
menudetailscell.taxlbl.text=@"(*Exclusive all taxes)";
}
menudetailscell.ratelbl.text=[NSString stringWithFormat:@"%@ %@",[[arr objectAtIndex:indexPath.row]valueForKey:@"country"],cost];
NSString *typeimgUrl1 = [NSString stringWithFormat:@"%s/presignin/menu/showMedia?idMenu=%@",urlPath,imgid];
NSURL *imageURL=[NSURL URLWithString:typeimgUrl1];
menudetailscell.imgview.imageURL=imageURL;
menudetailscell.selectionStyle = UITableViewCellSelectionStyleNone;
return menudetailscell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 70.0f;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
static NSString *CellIdentifier = @"Menusectioncell";
menusectioncell = ( Menusectioncell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (menusectioncell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Menusectioncell" owner:self options:nil];
menusectioncell = [nib objectAtIndex:0];
}
if (menusectioncell == nil)
{
menusectioncell = [[Menusectioncell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if ([arrSelectedSectionIndex containsObject:[NSNumber numberWithInteger:section]])
{
menusectioncell.Sectiomtitlebtn.selected = YES;
menusectioncell.dotlbl.hidden=NO;
}
else{
menusectioncell.dotlbl.hidden=YES;
}
menusectioncell.Sectiomtitlebtn.tag=section;
menusectioncell.dotlbl.layer.cornerRadius = menusectioncell.dotlbl.frame.size.height/2;
menusectioncell.dotlbl.layer.masksToBounds = YES;
[menusectioncell.Sectiomtitlebtn addTarget:self action:@selector(btnTapShowHideSection:) forControlEvents:UIControlEventTouchUpInside];
NSString *btntitle=[menuarray[section] valueForKey:@"catagory"];
itemarr=[menuarray[section] valueForKey:@"menu"];
NSString *items=[itemarr[0] valueForKey:@"name"];
menusectioncell.sectiontitleilb.text=btntitle;
menusectioncell.itemslbl.text=[NSString stringWithFormat:@"%@.,etc...",items];
menusectioncell.selectionStyle = UITableViewCellSelectionStyleNone;
return menusectioncell.contentView;
}
-(IBAction)btnTapShowHideSection:(UIButton*)sender
{
if (!sender.selected)
{
if (!isMultipleExpansionAllowed) {
[arrSelectedSectionIndex replaceObjectAtIndex:0 withObject:[NSNumber numberWithInteger:sender.tag]];
}else {
[arrSelectedSectionIndex addObject:[NSNumber numberWithInteger:sender.tag]];
}
menusectioncell.dotlbl.hidden=YES;
sender.selected = YES;
}
else{
sender.selected = NO;
menusectioncell.dotlbl.hidden=NO;
if ([arrSelectedSectionIndex containsObject:[NSNumber numberWithInteger:sender.tag]])
{
[arrSelectedSectionIndex removeObject:[NSNumber numberWithInteger:sender.tag]];
}
}
if (!isMultipleExpansionAllowed) {
[_tblview reloadData];
}else {
[_tblview reloadSections:[NSIndexSet indexSetWithIndex:sender.tag] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 75;
}
我只是想在主菜和向下细节之间留出空间,用于标题视图和我正在使用 2 个不同单元格的行。请帮我解决这个问题。