I try to keep the lower cells in front of the cells above them. I have a subview in a cell that ideally goes for the cell below. I am having trouble finding the code for this. I think I should use this piece of code:
for i in 0 ..< arrayWarningTitles.count{ let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: i, inSection: 0)) self.tableView.bringSubviewToFront(cell!) }
but I'm not sure where, since I tried several different places, and none of them worked (willDeselectRowAtIndexPath and didSelectRowAtIndexPath), and I will also like it on boot. Any suggestions would be greatly appreciated!
UPDATE (added table view code) :
Here is the main part of my table view code, if that helps someone, I deleted the above snippet as it does not work.
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 }
source share