1

I inherited an app to work on and the previous engineers didn’t use the storyboard and instead hard coded everything in. Now I’m at the point where I’m I have to change format and placement of items in the app and I feel it would be much easier to use the storyboard. Is their a way to use the storyboard still and have it display the stuff that is hard coded in the app right now?

I’ve attached images of me right clicking the storyboard and trying to the interface builder but nothing happens when I click it. Also I attached a photo of a code snippet that the other engineers claimed to have gotten rid of the need for a storyboard in the AppDelegate. I tried commenting out the line of code and when I do, the app is just a black screen.

The code in question reads:

var window: UIWindow? 

window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
Lokesh SN
  • 1,583
  • 7
  • 23
  • have you set up initial viewcontroller in storyboard? if not please refer the link https://stackoverflow.com/a/26224251/1142743 to do so – Vinodh Jul 31 '19 at 07:26
  • 3
    To learn how things are hooked up programmatically could be ***easier*** than redesigning the entire UI. – vadian Jul 31 '19 at 07:46

2 Answers2

0

Answer the question

Load rootViewController from storyboard by codes.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

    // ....        

    // Initilazie main window.
    let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let rootController = mainStoryboard.instantiateInitialViewController()!

    guard let w = self.window else { return true }

    w.rootViewController = rootController
    w.makeKeyAndVisible()
}


My suggestion

I will suggest to combine existed UI designed by codes and new UI designed by storyboard. Because UIViewController can be loaded from storyboard by codes. It could be combined to existed project easily.

// Example
let storyboard = UIStoryboard(name: "DeviceConfigStoryboard", bundle: nil)
let v = storyboard.instantiateViewController(withIdentifier: "upgrade_device") as! DCNavigationViewControllerBase
v.configure(device: device)

If google multiple storyboard, you could find many tutorial about dividing UI to multiple storyboard files, like this one.

AechoLiu
  • 17,522
  • 9
  • 100
  • 118
0

Add the name of your storyboard file in your Info.plist file.

If you don't find the key "UIMainStoryboardFile" in your info.plist, open the file as source code and add:

    <key>UIMainStoryboardFile</key>
    <string>Main</string>

This should set your storyboard as your starting point for the app. Make sure you have an initial ViewController in your storyboard.

Remark: I would still suggest you to stick with the code based UI, especially when you are working with multiple developers in your project. The convenience you may get while making storyboards may cost you valuable time in the long run.

SWAT
  • 1,107
  • 8
  • 19