Note that there are some explanatory texts on larger screens.

plurals
  1. POCombine code with view controller in Storyboard via instantiateViewControllerWithIdentifier
    text
    copied!<p>I'm learning Objective-C, and ran into something which doesn't make sense to me. </p> <p>When we have a view controller (VC) drawn in Storyboard, you can call this VC via code by entering a string into the Storyboard ID (click on the VC in Storyboard, in Utilities sidebar, Identity Inspector tab, Identity section) using the instantiateViewControllerWithIdentifier method.</p> <p>In my example, I've drawn a standalone UIViewController in Storyboard and set Storyboard ID to "orderList". In the code, I can call this view by this code, <strong>Code1</strong>:</p> <pre><code>UIViewController *ordersVC = [self.storyboard instantiateViewControllerWithIdentifier:@"orderList"]; </code></pre> <p>If I create a subclass of UIViewController called "SCVCOrders", and insert some code into it that modifies how it looks - like setting a title or changing the background color I thought I'd be able to use this code <strong>Code2</strong> to combine the drawn VC with the code in SCVCOrders:</p> <pre><code>SCVCOrders *ordersVC = [self.storyboard instantiateViewControllerWithIdentifier:@"orderList"]; </code></pre> <p>But it doesn't combine them. It only uses what is drawn in the Storyboard. So next, in Storyboard, I set the drawn VC's class to SCVCOrders. Now <strong>Code2</strong> gives me the combined look, but so does <strong>Code1</strong>. My conclusion from this is that Storyboard is taking precedence over the instantiation code. Xcode doesn't care what class I code the view to be, it will just look at Storyboard for this. Is this correct?</p> <p>I imagine it would be useful to have ability to layer my code on top of what I draw in Storyboard. Using my example, I'd like to leave my drawn VC as the generic class. And use <strong>Code2</strong> to layer code on top of the drawn VC. Or how else can we achieve something like this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload