I have a strange issue where I have a single view controller running different spriteKit scenes. In any of the given scenes, the method I am using to attach the subView is by passing an NSNotification to the view controller a reference to the view created in the scene.
If I navigate through my scenes to the UITextField without loading any UIWebViews, I have no issue. But if I load a UIWebView first, destroy it and then load the UITextField, i get the following crash:
[UIWebView respondsToSelector:]: message sent to deallocated instance
Structure:
Single View Controller creates and destroys all SKScenes
UIWebView Creation:
in the SKScene the view is created, and then a reference of the window is passed to the view controller via notification:
[[NSNotificationCenter defaultCenter] postNotificationName:@"addWebView" object:window];
The viewController then adds the window to the scene as follows
(by way of a registered observer):
- (void)addWebView:(UIWebView*)update {
[self.view addSubview:update];
}
Similarly the UIWebView is removed in the VC as follows via NSNotification:
- (void)removeWebView:(UIWebView*)update {
if (update) {
[update stopLoading];
[update setDelegate:nil];
[update removeFromSuperview];
}
}
Same method adding and removing the UIText View:
- (void)addUITextView:(UITextView*)update {
[self.view addSubview:update];
}
- (void)removeUITextView:(UITextView*)update {
if (update) {
update.delegate = nil;
[update removeFromSuperview];
}
}
So what i know is that FSR ios thinks there is still a webView. It is sending messages to it although it is deallocated and long gone, not even in the same scene.
I you see anything I am blatently doing wrong, I would appreciate the feedback. As per usual this is an excerpt from an app that is infinitely more complicated.
there is a working example available on github but I can't seem to post the link without being moderated. I will attempt to post it in a response.