[英]TableView with custom sections and cell
我有這種tableView,並且我有一個問題,就是我在每個部分的底部都有可見的分隔符。 如何刪除? 我需要在各部分的中間使用它,而不是在底部使用它。
我也需要節之間相同的空間。 我明白了。 我的密碼
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if(section == 0)
return 15;
return 1.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 14.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
return [[UIView alloc] initWithFrame:CGRectZero];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [[UIView alloc] initWithFrame:CGRectZero];
}
取代這個
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if(section == 0)
return 15;
return 1.0;
}
與
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if(section == 0)
return 0;
return 15.0;
}
並刪除這兩種方法
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
在viewDidLoad
處理分隔符
[self.tableView setSeparatorColor:[UIColor clearColor]];
在cellForRowAtIndexPath:
您可以根據自己的indexPath.row和indexPath.section值自定義分隔符視圖,例如
if(indexPath.row != self.yourArray.count-1)
{
UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0, yourCellHeight -2, 320, 2)];
line.backgroundColor = [UIColor redColor];
[cell addSubview:line];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.