2014-09-01 46 views
0

我有帶有多個部分的tableView。我想在行之間有分隔符,但不希望在分區的最後一行下面有分隔符。我怎樣才能實現它?檢測tableView部分中的最後一行並刪除分隔符

我的代碼也刪除了一個內部分隔符。

NSInteger totalRow = [tableView numberOfRowsInSection:indexPath.section]; 
if (indexPath.row == totalRow -1) 
{ 
    //v1 of code 
    UILabel *l = [[UILabel alloc]init]; 
    CGRect r = cell.bounds; 
    r.origin.y = r.origin.y + r.size.height - 2; 
    l.frame = r; 
    l.backgroundColor = [UIColor greenColor]; 
    [cell.contentView addSubview:l]; 
    cell.separatorInset = UIEdgeInsetsZero; 

    //v2 of code 
    cell.separatorInset = UIEdgeInsetsMake(10000.f, 0.f, 0.f, 1000); 

_http://i60.tinypic.com/15xpyqp.png

創建細胞是這樣的:

UITableViewCell *cellL; 
switch (indexPath.section) { 
    case 0: 
    { 
     switch (indexPath.row) { 
      case 0: 
      { 
       static NSString *CellIdentifier = @"PopPushCellIdentifier"; 
       PopPushCell *cell = (PopPushCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
       cell.pushTypeOn = YES; 
       cell.style = 5; 
       cell.titleLabel.text = [self returnTitleForCellWithTag:cell]; 
       return cell; 
      } 
       break; 

      case 1: 
      { 
       static NSString *CellIdentifier = @"TextFieldCellIdentifier"; 
       TextFieldCell *cell = (TextFieldCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
       cell.style = 4; 
       cell.titleLabel.text = [self returnTitleForCellWithTag:cell]; 
       return cell; 
      } 
       break; 
+0

什麼不工作?你有沒有嘗試調試代碼? – sha 2014-09-01 15:31:57

+0

如果我在代碼v1的單元格底部添加了白色分隔符,它也會添加到內部單元格中。如果我在代碼v2中設置底部單元格 - 它也設置爲內部。請參閱圖片 – 2014-09-01 15:33:20

+0

您是使用自定義單元格分隔符還是內置的單元格? – sha 2014-09-01 15:35:36

回答

0

一種方法來實現它是插入一個1個像素高度的UIView在你的細胞上。參考它(在Interface Builder上鍊接)並將其設置爲隱藏或不在您的代理上。

+0

它不起作用。我有它,即使我設置self.tableView.separatorInset = UIEdgeInsetsMake(0.0,self.view.frame.size.width,0.0,0.0);; – 2014-09-01 15:46:42

+1

這種方法應該可行,但你必須禁用UITableView上的默認分隔符 – Jasper 2014-09-02 13:44:50

+1

並且不要忘記給UIView一個backgroundcolor – Jasper 2014-09-02 13:45:30