iPhone UITableView : How to remove the spacing between sections in group style table?

后端 未结 9 945
南方客
南方客 2021-02-05 09:33

I am creating a table view in which there are 10 sections, all having a header view but no cells. So, in short, my table view will display 10 header views only; there will be no

相关标签:
9条回答
  • 2021-02-05 09:54

    Try with following code

    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
    {
        return 0.25; // as for you need
    }
    

    you can also manage by following delegate method

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    

    Is short you can manage it by above two method.

    0 讨论(0)
  • 2021-02-05 09:55

    Change the Table View style from Grouped to Plain. This solved my problem.

    0 讨论(0)
  • 2021-02-05 09:55

    Try using this :

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
       return 0;
    }
    

    As mentioned in comments, try using this :

     self.tableView.rowHeight = 0;
    
    0 讨论(0)
  • 2021-02-05 09:58

    You need to use method heightForHeaderInSection . You can also change it depending on different sections for eg. at some sections you may need to show more distance & under some, you don't want to show gap. For such case you can use CGFLOAT_MIN which is 0.000001f. Giving you an example, how you can use different section with different header heights

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
        if (section == 0 || section == 2)
        {
            return 55.0;
        }
        else
        {
            return CGFLOAT_MIN;
        }
    }
    

    Hope it will help you.

    0 讨论(0)
  • 2021-02-05 10:06

    Try this..

       self.tableView.rowHeight = 0; // in viewdidload
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; // in viewdidload
    
     -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
    {
    return 0.01f;
    }
    
    -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return <your header height>;
    }
    
    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [[UIView alloc] initWithFrame:CGRectZero];
    }
    
    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return <your header view>;
    }
    

    Also have table seprator as none.

    0 讨论(0)
  • 2021-02-05 10:07

    So I can not up vote but I can post a reply

    The correct answer to this way in fact

    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
         return CGFLOAT_MIN;
    }
    
    0 讨论(0)
提交回复
热议问题