2014-09-05 25 views
2

我試圖在右側設置分隔符插入。在項目的第一次運行和滾動tableview之前,一切都顯得平滑。但是,一旦滾動發生一次,每個部分中最後一行的分隔符插入將調整爲全部寬度。 使用的代碼如下: 在viewDidLoadUITableView分隔符插入在iOS7中滾動tableview時更改爲默認值

myTable.separatorColor = [UIColor redColor]; 
[myTable setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 40)]; 

cellForRowAtIndexPath

[tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 40)]; 
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 40); 

我試圖把相同的代碼在UITableView幾乎所有其他委託/數據源的方法,但都無濟於事。

UILabel *upperBorder = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 280.0, 1.0)]; 
[upperBorder setBackgroundColor:[UIColor blackColor]]; 
[headerView addSubview:upperBorder]; 

UILabel *lowerBorder = [[UILabel alloc]initWithFrame:CGRectMake(0, 39.0, 280.0, 1.0)]; 
[lowerBorder setBackgroundColor:[UIColor blackColor]]; 
[headerView addSubview:lowerBorder]; 

我已經把圖像:

若要執行插圖啄在表中的headerview,我已經在viewForHeaderInSection(標題爲40的高度)增加了兩個UILabel上部和下部具有受限框架寬度滾動前後。

滾動前: enter image description here

滾動後: enter image description here

在這方面的任何幫助表示讚賞。我只需要讓表格看起來像第一張圖片,即使在滾動之後也是如此,無論如何保留邊緣插入在右側。 在此先感謝。

回答

1

我也注意到該部分的最後一個單元格擴展爲全長,tableview將在您的自定義部分標題上繪製分隔線。因此,要隱藏該分隔線,您可以添加一個視圖來隱藏此分隔符。

UIView *hideLineView = [[UIView alloc]initWithFrame:CGRectMake(0, -1, 320, 1)]; 
hideLineView.backgroundColor = [UIColor whiteColor]; 
[headerView addSubview:hideLineView]; 

以上代碼中的whiteColor可以設置爲您的tableview背景色。

+0

非常感謝,工作正常:) – keepsmiling 2014-09-11 12:48:02