调整tableView的section间距的方法
设置
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
和
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
当为0.1时最小
希望这个从UITableViewDelegate协议里得到的方法可以对你有所帮助:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease];
if (section == integerRepresentingYourSectionOfInterest)
[headerView setBackgroundColor:[UIColor redColor]];
else
[headerView setBackgroundColor:[UIColor clearColor]];
return headerView;
}
过程`1.设置section的数目,即是你有多少个cell
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 3; // in your case, there are 3 cells}
2.对于每个section返回一个cell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 1;}
3.设置cell之间headerview的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 10.; // you can have your own choice, of course}
4.设置headerview的颜色
- (UIView )tableView:(UITableView )tableView viewForHeaderInSection:(NSInteger)section{ UIView *headerView = [[UIView alloc] init]; headerView.backgroundColor = [UIColor clearColor]; return headerView;}
注意:需要使用 indexpath.section 来获得index,而不是用 indexpath.row
cell.textLabel.text=[NSString stringWithFormat:@”%@”,[array objectAtIndex:indexPath.section]];
翻译整理自:
http://stackoverflow.com/questions/7189523/how-to-give-space-between-two-cells-in-tableview
`