0

I am making a custom setup for how I want to manage my view controllers which are managed by contexts. So I made my own custom controller class called Controller

//base controller class
class Controller:UIViewController{

}

And I have a context class which manages Controllers as such

//abstract base of context classes
class Context{

}

For my first class I am doing a photo editor so I made a C_TakePhoto class which inherits from Controller (which right now is just a carbon copy of UIViewController as you saw above)

//manages the take photo view class
class C_TakePhoto:Controller{

    override func viewDidLoad() {
        super.viewDidLoad()
        println("got here")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

To load this class I went to the AppDelegate and set it to load the context (the context just manages controllers)

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        var p:O_PhotoEditor = O_PhotoEditor()
        return true
    }

O_PhotoEditor is just a context that opens up a C_TakePhoto as such

//manages photo editor
class O_PhotoEditor:Context{

    var _photoEditorController:C_TakePhoto

    override init()
    {
        println("Init on O_PhotoEditor")
        _photoEditorController = C_TakePhoto()
        super.init()
    }
}

The "Init on O_PhotoEditor" does get printed in the console so I know 100% that this code is called. However if I go one line down into the C_TakePhoto class, the "got here" is not called in the viewDidLoad function.

Im pretty sure I need to present the view controller but I'm at a loss as to how with my custom classes.

When I started single view applications it just seemed to load the first one automatically.

Do know what step I am missing to have the viewDidLoad actually get called and to have the view appear?

Aggressor
  • 13,323
  • 24
  • 103
  • 182
  • 1
    I'm not sure what the steps are in swift to make this happen, but it looks like you haven't pushed your view controller onto a stack anywhere. Simply instantiating it does not inject it into the hierarchy. Without being put in a navigation controller's hierarchy, a view controller will not load its view. – Ian MacDonald Oct 08 '14 at 19:32
  • Could you link me to an example of doing this in Objc, I can easily translate that over to Swift – Aggressor Oct 08 '14 at 19:33
  • Are you using Storyboard, nibs or does your view controller set everything up programmatically? Once you have your vc, you can assign it to self.window.rootViewController. – Paulw11 Oct 08 '14 at 19:36
  • I will eventually be using the storyboard but for now Im just trying to get it up programmatically. the self.window, this looks like a UIWindow class. Where would I put this? In my context or my UIViewController? – Aggressor Oct 08 '14 at 19:38
  • In your `didFinishLaunchingWithOptions` you can say `self.window.rootViewController=p._photoEditorController` Storyboard will do this for you if you set the scene as "initial" in Interface Builder – Paulw11 Oct 08 '14 at 19:41
  • Ok cool, I added that, and I feel we are closer the issue, but the viewDidLoad still not called in C_TakePhoto – Aggressor Oct 08 '14 at 19:46
  • 2
    `viewDidLoad` isn't called if you aren't using a nib or storyboard scene - see http://stackoverflow.com/questions/8876300/viewdidload-method-in-uiviewcontroller-when-does-it-get-called – Paulw11 Oct 08 '14 at 19:50
  • Gotcha! Thank you, Im starting to see whats going on here. I called viewDidLoad manually and it did hit the code (even though its not appearing on the screen). I think will a little more digging I can figure out it. Thank you!!! – Aggressor Oct 08 '14 at 19:52
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/62698/discussion-between-paulw11-and-aggressor). – Paulw11 Oct 08 '14 at 19:54

0 Answers0