A layer is part of a loop in its iOS 9 Swift 2 tree layer

When I load my view controller, I get this error:

*** Terminating app due to uncaught exception 'CALayerInvalid', reason: 'layer <CALayer: 0x7fda42c66e30> is a part of cycle in its layer tree' 

I do not know why. I think that maybe I added a third-party structure that referenced the layers, but I deleted it in the troubleshooting process. Any ideas would be great.

EDIT

This happens during the viewDidLoad my tableViewcontroller . I have a tableView on my second vc. I narrowed it down to failure when setting heightForRowAtIndexPath on the 4th user cell. The cell is on a static tableView .................: / tableView closer!

Here is my heightForRowAtIndexPath :

 override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { print("idx = \(indexPath.row)") return super.tableView(tableView, heightForRowAtIndexPath: indexPath) } 

Pretty common. Any thoughts on where else this might be triggered?

+10
ios9 swift2 calayer
source share
7 answers

I also had the same error and found this fix

It mentions that you need to remove the accessoryView outlet that you will see in the TableView.

For this:

  1. Click on table view
  2. Go to the “Connection inspector”, in the right window, the most recent icon (looks like a circle with an arrow to the right)
  3. Look for an accessory View and unplug the outlet

The screen shot below shows the outlet that needs to be disconnected:

enter image description here

+12
source share

check if you added self.view to self.view, for example:

 self.view.addSubview(view) 

or

 contentView.addSubview(self.view) 
+24
source share

It may help someone still in trouble. For me the problem was this

 layer.addSublayer(layer) 

Adding a layer to yourself 🤦‍♂️. After this error, I plan to commit suicide :(.

+13
source share

I solved one crash of this kind by removing the output to File' s owner in some xib UI files. I answer here if someone comes across this.

+1
source share

One of my friends ran into the same problem. The main reason lay in the viewForHeaderInSection delegate of UITableview.

He added a label in the main window of the controller in this delegate. He had to create a UIView and return it to that delegate, but unfortunately he was returning himself. there. So removing this code solved the problem.

+1
source share

I managed to fix it, but not in the way I had hoped. I ended up scratching tableViewCell, which caused the problem and rebuilds all layout restrictions from scratch. Not perfect, but it worked. I hope someone can come in the future and explain why this error occurred! Greetings.

0
source share

I had this problem too, and I found that I accidentally created an output from the backgroundView of the TableViewCell into the TableView - DOH!

0
source share

All Articles