0

I have a NestedViewController which I am trying to push into a UINavigationController. This causes a crash with a following stack trace:

enter image description here

Additionally:

  • All of this is happening on the main thread
  • This reproduces both on iOS 11 and 12
  • animated flag doesn't change anything
  • NestedViewController gets modally presented somewhere else in the app and it does so successfully, without crashing
  • NestedViewController gets its layout from a storyboard
  • NestedViewController with its view initialized programmatically and identical to storyboards layout still causes a crash
  • Pushing an empty UIViewController doesn't cause a crash

What am I doing wrong?

UPD1: I made this yet this doesn't cause a crash:

let controlla = { () -> UIViewController in
    let cont = UIViewController()
    cont.view = {
        let view = UIView()

        view.backgroundColor = UIColor.green
        let stack = UIStackView(arrangedSubviews: [ {
            let view = UIView()
            view.backgroundColor = UIColor.yellow

            view.snp.makeConstraints { make in
                make.height.equalTo(128)
            }
            return view
        }() ])
        view.addSubview(stack)

        stack.snp.makeConstraints { make in
            make.top.leading.trailing.equalToSuperview()
        }

        return view
    }()
    return cont
}()

controller.pushViewController(controlla, animated: true)

UPD2: On the request of user Adeel in the comment here is what it says in the console upon an abort breakpoint hit:

libc++abi.dylib: terminating with uncaught exception of type NSException

If it was so simple and the message was there, this question wouldn't really exist, would it.

UPD3: So to extend my investigation I have uninstalled all of the views inside the view controller except for the root one.

enter image description here

The scene tree, while at it, started to look like this:

enter image description here

Then, of course, I got rid of all outlets and the code that was in the view controller.

It still crashes. The modal present still works fine though.

UPD4: I renamed the NestedViewController into some other name just in case. Didn't work.

UPD5: Before UPD1 it looked like this:

controller.pushViewController(controller, animated: true)
Isaaс Weisberg
  • 2,296
  • 2
  • 12
  • 28

2 Answers2

1

As stated in UPD5, the controller you are pushing into the navigation controller is literally that same controller itself.

Isaaс Weisberg
  • 2,296
  • 2
  • 12
  • 28
0

Check this stackOverflow

The crash info is obscure. Hope it can inspire you.

Andy Darwin
  • 478
  • 5
  • 19
  • Nope, this statement is unfortunately invalid. Missing outlets always result in an unrecognized key exception while trying to KVC, usually in `-[NSObject+ (NSKeyValueCoding) setValue:forKey:]`, which gets called in a course of `-[UIViewController loadView]`. This method might be called both before and after a modal presentation/nav controller push and thus this failure is independent of view controllers state. – Isaaс Weisberg Aug 07 '19 at 10:02
  • Spoiler: I know this for certain because I just happen to have a crash log where this exact case happened, unrelated to the flow in question. – Isaaс Weisberg Aug 07 '19 at 10:03
  • No idea. Check this and maybe it can inspire you. https://stackoverflow.com/questions/26442414/libcabi-dylib-terminating-with-uncaught-exception-of-type-nsexception-lldb – Andy Darwin Aug 07 '19 at 11:41