2015-03-03 56 views
0

我想隐藏在我的UITableView中的两个单元格下的灰线(分隔符),但是我遇到了麻烦。隐藏单个UITableViewCell分隔符

我有一个分组的UITableView,这是我的cellForRowAtIndexPath方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil]; 


    if (indexPath.section == 0) 
    { 
     if (indexPath.row == 0) { 
      // Date 
      if (cell == nil) 
      { 
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; 
      } 
      cell.textLabel.text = @"Date:"; 
      cell.detailTextLabel.text = currentDateString; 
     } else if (indexPath.row == 1) { 
// UIPicker 
      if (cell == nil) 
      { 
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
      } 
      cell.clipsToBounds = YES; 
      [cell.contentView addSubview:datePickerForCell]; 
     } 
    } else if (indexPath.section == 1) { 
     if (indexPath.row == 0) { 
// Order No. 
      if (cell == nil) 
      { 
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; 
      } 
      cell.textLabel.text = @"Order No:"; 
      cell.detailTextLabel.text = @"001-01989"; 
     } else if (indexPath.row == 2) { 
// Location 
      if (cell == nil) 
      { 
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; 
      } 
      cell.textLabel.text = @"Completed:"; 

      CGFloat optionalRightMargin = 10.0; 
      CGFloat optionalBottomMargin = 10.0; 

      completedByTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, cell.contentView.frame.size.width - 110 - optionalRightMargin, cell.contentView.frame.size.height - 10 - optionalBottomMargin)]; 
      self.completedByTextField.delegate = self; 
      completedByTextField.textColor = [UIColor grayColor]; 
      completedByTextField.tag = 2; 
      completedByTextField.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
      completedByTextField.textAlignment = NSTextAlignmentRight; 
      completedByTextField.placeholder = @"Name"; 
      completedByTextField.text = completedByString; 

      [cell.contentView addSubview:completedByTextField]; 
     } else if (indexPath.row == 3) { 
// Hours Worked 
      if (cell == nil) 
      { 
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; 
      } 
      cell.textLabel.text = @"Hours Worked:"; 
      cell.detailTextLabel.text = @"4 hrs 26 min"; 
     } 
    } else if (indexPath.section == 2) { 
     if (indexPath.row == 0) { 
// Description 
      if (cell == nil) 
      { 
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; 
      } 
      cell.textLabel.text = @"Description:"; 
     } else if (indexPath.row == 1) { 
// Description Textfield 
      if (cell == nil) 
      { 
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; 
      } 
      [cell.contentView addSubview:descriptionTextView]; 
     } 
    } else if (indexPath.section == 3) { 
     if (indexPath.row == 0) { 
// Materials 
      if (cell == nil) 
      { 
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; 
      } 
      cell.textLabel.text = @"Materials:"; 
     } 
    } 

    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; 
    } 

    return cell; 
} 

我想隐藏在隔板中的

//说明文本字段细胞

// Materials Textfield Cell(这个还没有写完,它只是我想表明将会有两个单元我想要做这两个n不只是一个,因为它可能会影响你的答案,我猜...)

我已阅读关于使用tableview.separatorcolor,但这改变了TableView中每个单元格分隔符颜色的颜色。

回答

0

你可以通过设置tableview偏移来隐藏行。

cell.separatorInset = UIEdgeInsetsMake(0.0, 45.0, 0.0, 0.0); 
1

据我所知,它不可能隐藏一些细胞的细胞分离器。它将适用于完整的表格视图。

但是,您可以通过在要隐藏分隔符的单元上添加透明或白色图像视图来实现此目的。保持图像视图大小比行高度大一点。可能是它应该帮助。

否则一般情况下它不可能隐藏某些单元格的单元格分隔符。如果您对特定分隔符进行了任何更改,它将反映在所有表格视图单元格分隔符中。

0

您无法触发分隔符来隐藏/取消隐藏UITableView的特定单元格。相反,完全禁用单元格分隔符并为您需要的单元格添加自定义分隔符。下面的代码添加到细胞,你需要显示在一个分隔符:

UIView* separatorView = [[UIView alloc] initWithFrame:CGRectMake(0, cell.contentView.frame.size.height-1, cell.contentView.frame.size.width, 1)]; 
separatorView.backgroundColor = [UIColor lightGrayColor]; // set custom color here 
[cell.contentView addSubview:separatorView]; 
0

您可以使用此行代码在你的cellForRowAtIndexPath方法 -

tableView.separatorStyle=UITableViewCellSeparatorStyleNone; 
+0

它将表的所有隔板被反映视图.... – 2015-03-03 06:49:02