Reputation: 9073
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)
}
Upvotes: -1
Views: 607
Reputation: 257711
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.
Upvotes: 0