0
votes

I have these 3 classes:

@interface BaseViewController : UIViewController
@interface BaseWebViewController : BaseViewController
@interface SecondaryWebViewController : BaseViewController

In AppDelegate, I am setting the rootViewController to be BaseWebViewController which will never be de-alloced throughout the entire lifetime of the app. In BaseWebViewController, I am calling [super viewDidLoad] and [super dealloc] in their respective methods.

Throughout most of the app, the user will be navigating through the UIWebView found on BaseWebViewController. But on certain links, I need to push (and later, pop out of) SecondaryWebViewController.

My question is that since both BaseWebViewController and SecondaryWebViewController are subclassing the BaseViewController, I'm not sure what to do regarding calling [super viewDidLoad] and [super dealloc] in SecondaryWebViewController.

In SecondaryWebViewController, I had been calling those [super viewDidLoad] and [super dealloc], but I noticed it caused some problems especially with random crashes when calling [super dealloc]. Since BaseWebViewController must always be present throughout the entire lifetime of the app, I don't ever want dealloc called on the BaseViewController.

Sorry, if this sounds confusing, but essentially, the flow looks like this:

  1. AppDelegate sets rootViewController to BaseWebViewController
  2. BaseWebViewController's viewDidLoad also calls the superclass BaseViewController's viewDidLoad
  3. Majority of the lifetime of the app is spent in BaseWebViewController, but occassionally SecondaryWebViewController needs to be pushed
  4. SecondaryWebViewController's viewDidLoad and dealloc calls the superclass's viewDidLoad and dealloc causing strange behaviour.

Currently, if I comment out [super viewDidLoad] and [super dealloc] in SecondaryWebViewController so that BaseViewController is never dealloced, then everything runs fine. However, I don't know if this is the right way of doing things.

What is the approach of calling super functions in a subclass such as this scenario?

1

1 Answers

2
votes

If I understood you correctly you are mixing the concepts of Classes and Objects.

By your description, you have two view controllers objects in your app. One of them is an instance of the BaseWebViewController class and the other is an instance of the SecondaryWebViewController class.

These two instances are completely separate from each other.

When your instance of SecondaryWebViewController calls dealloc, when it calls [super dealloc] this just invokes the dealloc method of the BaseWebViewController class - On the same instance. The other view controller instance is completely unaffected.

I might have completely misunderstood, and in that case please excuse me. If I did understand correctly, you should look up the concepts of classes and objects, this is really important basis for going on further.