2017-02-25 43 views
1

我在UITableviewCell有两个部分。我想隐藏那两个部分。 这是我的代码。如何隐藏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); 
} 

但它只是隐藏首节 显示如下图,我想是这样的(当卡是空的隐藏节,当我将产品添加到该卡显示所有(二)部分。) 帮助我,

显示第一张图片。 当我添加产品卡两个部分将显示,当我删除产品的所有部分将隐藏。 在此先感谢。

enter image description here enter image description here

回答

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的所有章节标题。

+0

你是如何识别你的车是空的?还是给我你的数组名的话,我可以在那里 –

0

另外不要忘记设置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; 
    } 
} 
+0

添加条件请说清楚你想在这里隐藏什么(在你的图片中)1.一张带有天蓝色背景和标题传送费用的视图,或者2.带有几条灰线的白色视图(令人垂涎的背景为中心)或3.底部蓝色区域(查看)与标题结帐? – 2017-02-25 06:22:36

+0

是的,但你在这个图像中的部分。一个视图与天空蓝色背景和标题交付费用是部分或您已添加单独的视图?带有几条灰线的白色视图(背景为中心背景)是行分隔符(表示行),而不是分节。 PL。说清楚,你在这个图片中的部分 – 2017-02-25 06:31:46

+0

Sry为你的麻烦,我是新的ios。 –

0

使用开关箱来处理多段高度。

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 
} 
1

在heightForHeaderInSection的tableview委托方法只返回0 ...

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { 
    // Specific section 
    if (section == 0) 
      return 0.0f; 

    // all sections 
    return 0; 
} 
相关问题