last day (15 days later) » 

7:54 PM
0
Q: Custom UIViewController viewDidLoad() Not Getting Called

AggressorI 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 //abstra...

 
Could you link me to an example of doing this in Objc, I can easily translate that over to Swift
 
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.
 
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?
 
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
 
Ok cool, I added that, and I feel we are closer the issue, but the viewDidLoad still not called in C_TakePhoto
 
7:54 PM
viewDidLoad isn't called if you aren't using a nib or storyboard scene - see stackoverflow.com/questions/8876300/…
 
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!!!
Oh thanks for the help XD
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
var p:O_PhotoEditor = O_PhotoEditor()
self.window?.rootViewController = p._photoEditorController
p._photoEditorController.loadView()
p._photoEditorController.viewDidLoad()
return true
}
Thats my current code, but its saying I shouldnt call loadView at all
 
When you say it isn't appearing in the screen, I would expect you to get a black screen from the code here as you aren't adding anything to your view controllers view
 
Correct its black haha
But viewDidLoad is called (as I called it manually which I doubt Im supposed to)
Heres the view controller code tho
I shorterned it for the post
var image:iImage!
var text:iText!

override func viewDidLoad() {
super.viewDidLoad()
println("got here")
/* image = iImage(imageName: "jenny1.jpg")
self.view.addSubview(image)
image.drawViewBorder(true)
image.setDragView(self.view)
image.drag = true
image.canZoom(true)*/

text = iText(text:"Mwahah I am the very modlela of f a moerh sdfkhsdkfjs df")
self.view.addSubview(text)
text.drawTextBorder(true)
text.setDragView(self.view)
text.drag = true
text.y = 100
}
If I set the build to use the Main.Storyboard I get this view loading up just fine in the default ViewController.swift file
But this carbon copy in my C_PhotoEditor is not quite working
 
If you aren't using a nub or storyboard then you need to override loadView. From the docs - You can override this method in order to create your views manually. If you choose to do so, assign the root view of your view hierarchy to the view property. The views you create should be unique instances and should not be shared with any other view controller object. Your custom implementation of this method should not call super.
So the code you have in viewDidLoad moves to your overridden loadView - but before you can say self.view.addSubView... you have to assign something to self.view - probably a plain UIView the full size of your window
 
Ahhh
Let me try that right now
I assume I can use the var window: UIWindow? that the app delegate gives me?
 
8:03 PM
Yes
 
Or should I create a new UIView the size of the screen?
 
It is better to use the window frame as this will reflect the screen size of the current device
But it needs to be a new UIView of that size. You can't just use the window - sorry, I misunderstood your question at first
 
ok gotcha so Ill create a UIView
using the dimensions of the UIWindow
Hmm so I need to do anything else in loadView
Still black screen
I assigned self.view to a UIView
but do I need to assign this view to something to get it to present?
(I called super.loadView() at the bottom but still nothing)
override func loadView()
{
println("got here")


self.view = UIView(frame:UIScreen.mainScreen().bounds.standardizedRect)

text = iText(text:"Mwahah I am the very modlela of f a moerh sdfkhsdkfjs df")
self.view.addSubview(text)
text.drawTextBorder(true)
text.setDragView(self.view)
text.drag = true
text.y = 100

super.loadView()
}
and in my AppDelegate I do call this loadView()
 
8:29 PM
That should do it, bit by default you will have black text on a black view. Try setting self.view.backgroundColor=UIColor.whiteColor also, don't call super.loadView(). Refer to the doc I pasted above
 
Ah ok let me fiddle with then I should be able to get it working
Hmmm
It seems to be stuck in an infinite loop calling loadView haha
I think I better do some deep digging in the apple documents again
(they're just so bloody long and convoluted haha)
 
8:46 PM
I 100% have a working window
I assigned that window.rootController to my C_TakePhoto:UIViewController class
Inside of C_TakePhoto's loadView I assigned its view as a new UIView
And I set the background color to white
Do I need to assign the self.view (inside C_TakePhoto) anywhere else?
Do I need to addSubview somewhere here?
I even added the self.view to the UIWindows subviews...
OMFG
I got it working
I needed to do this
override func loadView()
{
self.view = UIView(frame:UIScreen.mainScreen().bounds)
println("got here \(self.view)")
self.view.backgroundColor = UIColor.whiteColor()
window.addSubview(self.view)
window.makeKeyAndVisible()

text = iText(text:"Mwahah I am the very modlela of f a moerh sdfkhsdkfjs df")
self.view.addSubview(text)
text.drawTextBorder(true)
text.setDragView(self.view)
text.drag = true
text.y = 100

}
it needed a makeKeyAndVisible() call
or a window.hidden = false
If you want to post that snippet
1. Make a UIWindow the size of the screen
2. Assign the rootController of the window to my view controller
3. Make a UIView in the view controller and add it as a subView to the UIWindow
4. Set the UIWindow.hidden to false or call UIWindow.makeKeyAndVisibile
Id be happy to mark that correct as your answer
As it was thanks to your help I figured it out
 

last day (15 days later) »