gpt4 book ai didi

ios - 将 UITableViewCell 保持在其他单元格的前面

转载 作者:搜寻专家 更新时间:2023-10-30 22:18:44 26 4
gpt4 key购买 nike

我试图将较低的单元格保持在它们上方的单元格的前面。我在一个单元格中有一个 subview ,最好放在下面的单元格后面。我无法找到将代码放在哪里来执行此操作。我想我应该使用这段代码:

for i in 0 ..< arrayWarningTitles.count{
let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: i, inSection: 0))
self.tableView.bringSubviewToFront(cell!)
}

但我不确定在哪里,因为我尝试了几个不同的地方,但都没有奏效(willDeselectRowAtIndexPath 和 didSelectRowAtIndexPath),而且我也希望在初始加载时使用它。任何建议将不胜感激!

更新(添加 TableView 代码):

这是我的大部分 TableView 代码,如果它对任何人有帮助,我已经删除了上面的代码片段,因为它不起作用。

 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
selection = indexPath.row
tableView.beginUpdates()
tableView.endUpdates()
// self.tableView
}

override func tableView(tableView: UITableView, willDeselectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
tableView.beginUpdates()
tableView.endUpdates()


return indexPath;
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.selectionStyle = UITableViewCellSelectionStyle.None
cell.backgroundColor = UIColor.clearColor()
// Configure the cell...

let warningTitle = self.view.viewWithTag(1) as? UILabel
let expirationTime = self.view.viewWithTag(2) as? UILabel
let textView = self.view.viewWithTag(5) as? UITextView
let grayBackground = self.view.viewWithTag(6)
let redBackground = self.view.viewWithTag(7)

warningTitle?.text = arrayWarningTitles[indexPath.row]

redBackground!.layer.masksToBounds = true;
redBackground!.layer.cornerRadius = 20;
grayBackground!.layer.masksToBounds = true;
grayBackground!.layer.cornerRadius = 20;

redBackground?.clipsToBounds = false;
cell.clipsToBounds = false;
cell.contentView.clipsToBounds = false;
cell.contentView.superview?.clipsToBounds = false;
self.tableView.bringSubviewToFront(cell)
return cell
}

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


if (indexPath.row == selection) { //change 0 to whatever cell index you want taller
return UIScreen.mainScreen().bounds.height - 140 - 64;
}
return 58;//Choose your custom row height
}

最佳答案

听起来好像为 UICollectionView 自定义布局会更好。

我建议看一个项目 such as this one并以最适合您的方式修改代码。

关于ios - 将 UITableViewCell 保持在其他单元格的前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38336838/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com