Assertion message: Ignoring attempt to add focus items in already-visited container. This can potentially cause infinite recursion.

Searching Google (let alone this forum) returns zero results. Does anyone know what causes this error message and how to resolve it (or whether it's safe to ignore)?

Thanks!

Replies

Hello, could you please provide more information about what you are doing when you hit this message? Is this Objc, Swift, SwiftUI? Can you share more about the view/APIs you have set up? Is this a message that gets logged or something you see as a warning/error in Xcode?

This is a UIKit app written in Swift.

The issue seems to come up when calling addArrangedSubview(_:) on a UIStackView that is later set as the tableHeaderView or tableFooterView in a UITableView.

If you add the following viewDidLoad() to a plain old UITableViewController, it reproduces the issue in Xcode 14.3.1 on a simulator running iOS 16.4:

    override func viewDidLoad() {
        super.viewDidLoad()

        let headerView = UIStackView(frame: .zero)

        headerView.bounds = CGRect(origin: .zero, size: CGSize(width: self.tableView.bounds.width, height: 320))

        let label = UILabel(frame: .zero)

        headerView.addArrangedSubview(label)

        self.tableView.tableHeaderView = headerView
    }