iOS 在TableView的Cell之间设置空白间隔空间

时间:2014-08-12 22:08:04   收藏:0   阅读:631

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

iOS 在TableView的Cell之间设置空白间隔空间,布布扣,bubuko.com

原文:http://blog.csdn.net/willyang519/article/details/38521057

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!