I am trying to keep the lower cells in front of the cells above them. I have a subview in a cell that would ideally go behind the cell below. I am having trouble finding where to put the code to do this. I think I am supposed to use this snippet of code:
for i in 0 ..< arrayWarningTitles.count{
let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: i, inSection: 0))
self.tableView.bringSubviewToFront(cell!)
}
but I am not sure where, as I have tried a few different places and none have worked (willDeselectRowAtIndexPath and didSelectRowAtIndexPath), and I would also like it on the initial load up as well. Any suggestions would be greatly appreciated!
UPDATE (Added Table View Code):
Here is the bulk of my Table View code, if it helps anyone, I have removed the above snippet as it is not working.
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
}
It sounds as though you would be far better served with a a custom layout for UICollectionView
.
I would recommend looking at a project such as this one and modifying the code in whichever way would serve you best.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With