这只是设置行间距的一个方法。可以参考一下
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row % 2 == 0) { //判断奇数偶数行,奇数行为空格
CGRect rect = [[UIScreen mainScreen] bounds];//获得系统屏幕大小
CGSize size = CGSizeMake(rect.size.width, 52.0f);//设置行的高度
return size.height;
}else{
CGRect rect = [[UIScreen mainScreen] bounds];
CGSize size = CGSizeMake(rect.size.width, 10.0f);//设置空行的高度
return size.height;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (indexPath.row % 2 == 0) { //判别奇偶行
//设置cell值
}else{
//设置空值
}
return cell;
}
当然要注意返回的行列值也应该2倍的数据行减去1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 数据行*2-1;
}