Ios 如何在UITableViewcell(分组样式)中隐藏所有节标题?
我在Ios 如何在UITableViewcell(分组样式)中隐藏所有节标题?,ios,objective-c,uitableview,height,Ios,Objective C,Uitableview,Height,我在UITableviewCell中有两个部分。我想把那两部分藏起来。 这是我的密码 -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (section == 0) { return CGFLOAT_MIN; } else { return 32.0f; } } - (NSInteger)numberOfSectionsInTableVie
UITableviewCell
中有两个部分。我想把那两部分藏起来。
这是我的密码
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 0)
{
return CGFLOAT_MIN;
}
else
{
return 32.0f;
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [storename2 count];
}
- (NSString *)tableView:(UITableView *)tableViewtitleForHeaderInSection:(NSInteger)section
{
if (section == 0)
{
return nil;
}
else
{
return [storename2 objectAtIndex:section];
}
}
在Viewdidload中
- (void)viewDidLoad
{
[super viewDidLoad];
self->CartTableview.contentInset = UIEdgeInsetsMake(-1.0f, 0.0f, 0.0f, 0.0);
}
但它只隐藏了第一部分,
下面显示我想要的图片(当卡片为空时隐藏部分,当我向卡片添加产品时显示全部(两个)部分。)
帮帮我
显示第一个图像。
当我将产品添加到卡中时,将显示两个部分,当我删除产品时,所有部分将隐藏。
提前谢谢
我想你需要改变一下下面的方法
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
并删除此方法
- (NSString *)tableView:(UITableView *)tableViewtitleForHeaderInSection:(NSInteger)section
{
if (section == 0)
{
return nil;
}
else
{
return [storename2 objectAtIndex:section];
}
}
这将隐藏tableview中的所有节标题。也不要忘记设置UITableview委托和数据源
- (void) viewDidLoad {
[super viewDidLoad];
self.tableView.contentInset = UIEdgeInsetsMake(-1.0f, 0.0f, 0.0f, 0.0);
}
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
// Specific section
if (section == 0)
return 0.0f;
// all sections
return 0;
}
- (NSString*) tableView:(UITableView *) tableView titleForHeaderInSection:(NSInteger)section
{ // Specific section
if (section == 0) {
return nil;
} else {
// all sections
// return some string here ...
return nil;
}
}
使用开关箱处理多段高度
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
let headerHeight: CGFloat
switch section {
case 0:
// first section for test - set value for height
headerHeight = 0
default:
// other Sections - set value for height
headerHeight = 0
}
return headerHeight
}
只需在heightForHeaderInSection tableview委托方法中返回0
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
// Specific section
if (section == 0)
return 0.0f;
// all sections
return 0;
}
请明确你想在这里隐藏什么(在你的图片中)1。天蓝色背景和标题交付费用或2。带有几条灰线的白色视图(中间有凹陷的背景)或带有标题签出的3.底部蓝色区域(视图)?是的,但您在这张图像中的部分是什么。有天蓝色背景和标题交付费用的视图是第节还是您添加了单独的视图?带有多条灰线(中心凹形背景)的白色视图是行分隔符(表示行),而不是剖面。请说明,您在这张图片中的部分是什么为了您的麻烦,我是ios.Np的新手,请告诉我,这张图片中的部分是什么是的,这是。。。我是对的,它们是你的tableview行分隔符。此时(当您的表/购物车为空时),隐藏您的表或从tableview中删除行分隔符。您如何确定购物车为空?或者给我您的数组名称,然后我可以在其上添加条件。对于我来说,返回0.1的节头高度是有效的。