簡體   English   中英

具有自定義節和單元格的TableView

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM