Custom UIViewController subclass only shows a black screen - ios

I have created a subclass of UIViewController called LoginController. I have a LoginController.xib file that contains a view controller with a few elements in it. I have set the class of the view controller to LoginController and I have set my Main Interface to LoginController. Upon launching my app, I see my splash screen, followed by a pure black screen. My LoginController class just has the default code like so
class LoginController: UIViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
}

I just created a new xcode project. My results are totally normal. So I guess it's because you are not setting the LoginController.xib as the initial xib to load?

Related

Swift: Default Storyboard background Image for all ViewControllers

Is there a way to set (preferably in storyboard IB) an image, which, will serve as the background image for all ViewControllers in the whole storyboard. I don't want to have to add a background image in every ViewController or replicate that in code.
I would could create a UIViewController subclass (e.g. name it DefaultViewController) that sets a specific background color in one of the initialization methods (e.g. viewDidLoad, but don't forget if you override this in a subclass of this class to call it's super method).
Then, let all your view controllers inherit from DefaultViewController
Example code:
class DefaultViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = = UIColor.redColor()
}
}
class SomeViewController: DefaultViewController {
override func viewDidLoad() {
// this call makes the background red, you can also not override this method and it will work too
super.viewDidLoad()
}
}

Cannot override "preferredDisplayMode" in SplitView

I have an app with multiple UISplitViewControllers that each have their own MasterView and DetailView. I noticed, however, that when I launch right into one of the SplitViews, I get presented with the DetailView, and have to navigate back to the MasterView first. I would like to change that, and found out that this works with the preferredDisplayMode, but setting it somehow causes problems.
I've create a subclass of UISplitViewController for all three SplitViews, and tried overriding the preferredDisplayMode like this:
import UIKit
internal class SplitViewController : UISplitViewController {
#IBAction internal func unwindToSplitView(segue: UIStoryboardSegue)
override let preferredDisplayMode = UISplitViewControllerDisplayMode.PrimaryOverlay
}
However, I get the following error:
Cannot override with a stored property 'preferredDisplayMode'
What am I doing wrong? Thanks.
You should instead override the func viewDidLoad() and set preferredDisplayMode to the value that you want in there. Like so:
override func viewDidLoad() {
super.viewDidLoad()
preferredDisplayMode = .PrimaryOverlay // Or UISplitViewControllerDisplayMode.PrimaryOverlay if you prefer (both are equivalent)
}

Is it possible to wire up a custom UIImagePickerController class with a viewController on the storyboard

I want this class to wire up with a storyboard scene. The current result is that my storyboard view controller displays my saved photos album. i want to customise this class so it displays the camera. Is there a way to do this here without having to create a UIViewController class and create and display a UIImagePickerController within that? Reason being is I am using a UIPageController so dont want to have to call a modal imagepickervc.
class CameraViewController: UIImagePickerController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
From the UIImagePickerController class reference
IMPORTANT
The UIImagePickerController class supports portrait mode only. This
class is intended to be used as-is and does not support subclassing.

Custom segue not working in iOS 9.1

I'm trying to create a custom segue. It doesn't work in the first time. I found a solution afterward by creating a new file extends UIStoryboardSegue and create a method called "perform". It works right now without using prepareSegue in ViewController. I'm copied my previous codes from preparedSegue to "Perform" func in new UIStoryboardSegue file. It print out the message but the delegate doesn't work.
View Controller
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Custom Segue
class CustomSegue: UIStoryboardSegue {
let transitionManager = TransitionManager()
override func perform() {
NSLog("Perform");
let toViewController = self.destinationViewController as UIViewController
toViewController.transitioningDelegate = self.transitionManager
}
}
I placed breakpoint in every func in Transition Manager, none of them execute and stop.
Segue settings:
Problem: TransitioningDelegate is not working
Full sources codes: here
The problem is that your perform implementation doesn't do anything:
override func perform() {
let toViewController = self.destinationViewController as UIViewController
toViewController.transitioningDelegate = self.transitionManager
}
All you do is create a view controller, give it a transitioning delegate, and then throw it away. You do not perform any transition! But that is exactly the job of a segue. It isn't clear what you can possibly be expecting to happen.
If the idea is that this is supposed to be a present (modal) segue, then you should make it a present (modal) segue in the storyboard, specify your custom segue class, and then, in your perform implementation, call super to do the actual presentation:
override func perform() {
let toViewController = self.destinationViewController as UIViewController
toViewController.transitioningDelegate = self.transitionManager
super.perform() // this will work, _if_ you have specified a present (modal) segue
}
Alternatively, your perform could perform the presentation itself, by calling presentViewController:... on the source view controller with the destination view controller as parameter.
But your perform does nothing. Nothing will come of nothing.

Storyboard Content Not Showing

I'm working with storyboards for my views in a Swift app. I just created a new view controller and made it a class of StreamViewController. For some reason, no content is showing on the storyboard when I simulate the app? The only thing I've added in the storyboard is a Navigation bar.
StreamViewController.swift
import UIKit
class StreamViewController : UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
Storyboard Settings

Resources