IOS: is it possible to associate one ad panel view controller with several different classes?

I know that you can connect a custom view controller class to several different view controllers on a storyboard, but this can be done in a different direction; that is, depending on the situation, I want to associate different custom classes with one storyboard view controller, which will be created with:

[self.storyboard instantiateViewControllerWithIdentifier:] 

background: I used to have several view controllers that are almost identical. In fact, the user classes to which they are attached are also very similar. To clear this up, I reorganized my custom classes into one base class and several subclasses. Then I removed all the similar view controllers from the storyboard, leaving only one that I limited to my base class. Then I call:

 MySubclass* mySubclass = [self.storyboard instantiateViewControllerWithIdentifier:@"StoryboardControllerBoundToBaseClass"]; 

Unfortunately, my subclass code is ignored, and only the base class code is executed. Does anyone know how I can make it work without duplicating the view controllers on the storyboard and linking each of them to a different subclass?

+4
source share
3 answers

Instead of using a subclass, I suggest that I can reuse the view controller on the storyboard using the delegate / proxy model. More specifically, I can bind the storyboard view controller to a user class that delegates all its methods / events to other classes that will be processed. It's not as elegant as subclasses, but at least I can keep my storyboards more compact without having to store multiple copies of almost the same controller. In addition, I will not need to duplicate future changes for each copy of these controllers for download.

+1
source

It's impossible. Just because you say MySubclass * object = something does not magically convert the object into a MySubclass object. It is stored in the storyboard with any class assigned during compilation of the storyboard.

+2
source

As guylegend writes. Apple does not support the way to do this. There are many workarounds, for example. with delegates, but I finally found the answer and answered in another thread. Hope it helps! fooobar.com/questions/64836 / ...

0
source

Source: https://habr.com/ru/post/1445891/


All Articles