I'm currently having some difficulty presenting a view when my 3dTouch shortcut item is activated.
I'm attempting to present a view when the user uses the shortcut item 'Add Note'.
When activating the 'Add Note' shortcut item my application crashes and gives me the error: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
Here is the code: (App Delegate)
var cVC = ContainerVCViewController()
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
if shortcutItem.type == "DarthDevelopments.noteapp.addNote" {
//Prefrom Action Go To Add Note View
cVC.anim1in()
}
if shortcutItem.type == "$(PRODUCT_BUNDLE_IDENTIFIER).createList" {
//Prefrom Action Go To Create List View Controller
}
}
Here is the code: (ContainerVCViewController)
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var notesLabel: UILabel!
@IBOutlet var addNoteView: UIView!
@IBOutlet weak var addNoteText: UITextField!
@IBOutlet weak var blurView: UIVisualEffectView!
func anim1in() {
blurView.isHidden = false
view.addSubview(addNoteView)
addNoteView.center = self.view.center
addNoteView.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
addNoteView.alpha = 0
UIView.animate(withDuration: 0.4) {
self.addNoteView.alpha = 1
self.addNoteView.transform = CGAffineTransform.identity
}
}
While debugging I can see that while calling cVC.anim1in()
all the IBOutlets are equal to nil.
Here is what I'm receiving from the console:
Note:
I've been going over this for quite a while and I have come up with these conclusions:
- I need to be able to initialize all the IBOutlets
- Find a new method of presenting the 'AddNote View'
If anyone can come up with a solution to one of these ideas or another solution, that would be great!
Iām somewhat of a new developer. Sorry if I'm making a silly mistake.
Any help would be much appreciated.
Thank you for your time,
DarthShmev.
Important:
I've come up with somewhat of a solution thanks to Agility Vision.
Here is the post: StackOverFlow Topic
What he is basically saying is that I would need to:
- Create a UIWindow with a transparent UIViewController and then presenting the view on it.
I'm not sure to how to apply this in my situation though.