How to give space between two cells in tableview?

前端 未结 26 1478
谎友^
谎友^ 2020-11-29 00:11

I want a space between two cell in table view,

I want cell like this,

\"enter<

26条回答
  •  温柔的废话
    2020-11-29 00:59

    The Best way to get space between two cells in TableView, declare the numbers of sections you want in delegate method of numberofsections this way

    For example you have array of 10 objects

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      return [array count]; //array count returns 10
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
        return 1;// this should be one because it will create space between two cells if you want space between 4 cells you can modify it.
    }
    

    Then the important point is in cellForRowAtIndexPath delegate method you need to use indexpath.section but not indexpath.row

    cell.textLabel.text=[NSString stringWithFormat:@"%@",[array objectAtIndex:indexPath.section]];
    

    That is is check your tableview for the space between two cells. Enjoy!

提交回复
热议问题