Search code examples
iosobjective-ciphonexcode5

Tableview Header issue


I'm trying to give space between cells in my tableview for that i written the following code:

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    switch (section)
    {
        case 0:
            return 0.0f;
        break;


        default:
            return 15.0f;
        break;
    }

    return 15.0f;
}

up to now everything is fine, but after scrolling tableview gap is not moving when it reaches to top to table. My screens are:

 before scrolling after scrolling to top


Solution

  • You should not use header view for this purpose. Just design you cells so that their subviews (labels, buttons, images...) are contained in a view that is smaller than the cell itself and centered horizontally. Make the cell background grey, and the subviews' view container white.