-1

I was running an app on iPhone XR with iOS Version 13.2 using XCode 11.2 and the app crashes with reason.

reason: 'The return values of -viewForFirstBaselineLayout and -viewForLastBaselineLayout must be in the receiver's subtree

I tried searching but couldn't find the solution here: https://forums.xamarin.com/discussion/17633/nsinternalconsistencyexception-any-ideas-on-what-is-causing-this

I don't know what files I need to post here for this issue. So please mention in the comment if any file is required to understand this.

func removeSubviews() {
        for subview in self.subviews {
            subview.removeSubviews()
            subview.removeFromSuperview()//this line is causing crash.
        }
        self.removeConstraints(self.constraints)
    }
Mayur Gajra
  • 8,285
  • 6
  • 25
  • 41
  • have you added the exception break point? you may get the line which is causing the error. – Mahendra Jan 03 '20 at 07:28
  • Show your code for `viewForFirstBaselineLayout`. – matt Jan 03 '20 at 08:06
  • @matt There is no such file as `viewForFirstBaselineLayout` but I think the above-mentioned code is causing the issue. is there any way to resolve the issue? – Mayur Gajra Jan 03 '20 at 08:36

1 Answers1

0

The removing always should be in reverse order to adding. So view added to superview and then activated constraints, thus I would do it as

func removeSubviews() {
        self.removeConstraints(self.constraints)
        for subview in self.subviews {
            subview.removeSubviews()
            subview.removeFromSuperview()
        }
    }

also you should check other things you add, when constructing view hierarchy, so if any other cross-references created then they should be also destroyed, again - in reverse order.

Asperi
  • 228,894
  • 20
  • 464
  • 690