Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set custom class name to storyboard programmatically

I am trying set custom class name to storyboard programmatically in iOS.

I have storyboard with viewcontroller MyFirstViewController and set class name as MyFirstViewController

Now I create another viewcontroller SecondViewController which extends MyFirstViewController

 SecondViewController *vcsecond = (SecondViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"MyFirstViewController"];
        [self.navigationController pushViewController:vcsecond animated:YES];

When I run this app my SecondViewController viewDidLoad method not call, it calls MyFirstViewController viewDidLoad method.

I get vcsecond as object of MyFirstViewController.

Please help me how to open SecondViewController using MyFirstViewController XIB.

I only want to inherit all the functionality of MyFirstViewController to SecondViewController and also override some method's here and execute some new code in overrided method with additional functionality.

Design of the both viewcontroller is same only add some new functionality using overriding method's.

Please refer this

In above screen TabSearchForDocViewController is my MyFirstViewController controller.

So my actual question is----------

I have comman storyboard page for two view controller. My SecondViewController is extends MyFirstViewController. Now I want to open my SecondViewController using comman storyboard page. Is it possible to set class name programmatically?

like image 550
Arvind Kanjariya Avatar asked Nov 23 '22 01:11

Arvind Kanjariya


1 Answers

instantiateViewControllerWithIdentifier will always return an instance of the class specified in the corresponding scene in the storyboard - you cannot override this at run time.

I would suggest that you create a 'thin' object which is the class that you specify in the storyboard scene. You can then create other object classes (using inheritance) that implement the view controller functionality using a delegation pattern. You can then instantiate the appropriate delegate instance at run time.

like image 100
Paulw11 Avatar answered Nov 24 '22 15:11

Paulw11