ios - UITableViewCells "shines"槽的可扩展内容

标签 ios uitableview swift

我刚刚制作了一个 UITableView,点击它们时带有可展开的单元格。展开后,单元格显示 UIDatePicker

展开本身工作正常,但只有在单元格展开时才应该可见的单元格内容有点透过单元格闪耀。这是我正在谈论的内容的屏幕截图: enter image description here

单元格 1 已展开,而其他单元格未展开。如您所见,它们的可展开内容是可见的,但实际上不应该是可见的。

这是我使用的代码:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    var cellIdentifier = "Cell";

    var cell: NewExpenseTableCell;
    var array: NSArray = NSBundle.mainBundle().loadNibNamed("Cell", owner: self, options: nil);

    cell = array.objectAtIndex(0) as NewExpenseTableCell;
    cell.backgroundColor = UIColor.whiteColor();

    cell.descriptionLabel?.text = descriptionLabels[indexPath.item];

    return cell;
}

var selectedRowIndex = -1;

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    if selectedRowIndex == indexPath.row {
        selectedRowIndex = -1;
    } else {
        self.selectedRowIndex = indexPath.row;
    }
    newExpenseTable.beginUpdates();
    newExpenseTable.endUpdates();
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

    if indexPath.row == selectedRowIndex {            
        return 206;
    }       
    return 55;
}

谁能告诉我如何确保 UIDatePicker 仅在单元格展开时可见?

最佳答案

以下是我建议的使单元重用正常工作的方法。

  1. 打开 NewExpenseTableCell 的 .xib 文件。转到属性检查器,输入“NewExpenseTableCell”作为标识符。

  2. 在 View Controller 的 viewDidLoad 方法中,像这样注册 nib:

    self.tableView.registerNib(UINib(nibName: "NewExpenseTableCell", bundle: nil), forCellReuseIdentifier: "NewExpenseTableCell")
    
  3. cellForRowAtIndexPath 方法中,将前四行替换为:

    var cell = tableView.dequeueReusableCellWithIdentifier("NewExpenseTableCell") as NewExpenseTableCell
    

关于ios - UITableViewCells "shines"槽的可扩展内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27113526/

相关文章:

ios - Paytabs iOS SDK zip 集成

ios - 根据文本内容的高度设置单元格的高度

ios - 无法在 Interface Builder 的单元格中移动内容 View

ios - 基类实现tableView时如何使用UITableViewAutomaticDimension :heightForRowAtIndexPath:

ios - 我如何才能检测到用户是否仍然在 firebase 中有一个身份验证 session ?

ios - 如何获取 UIImageView 中图像的右上角和左下角坐标

ios - iOS5 中 icloud 的核心数据

swift - 我在滚动时更改了 UITableViewCell 不透明度,但用户交互有一两秒的延迟。我怎样才能解决这个问题?

c - 如何从 UnsafeMutableRawPointer 获取页对齐地址?

iphone - 如何检查 UITextfield 是否输入了数据?