Reputation: 899
I'm still trying to get to grips with linking UIViewControllers
etc in iOS
. I've had a ridiculous number of issues with segues but that will be my fault for getting thrown in at the deep end with hardly any training at all!
Anyway, I currently have a prepareForSegue
that runs every line perfectly and then should head via a UINavigationController
to the destination. However the destination UIViewController
doesn't show and the app silently crashes - no errors at all.
Is there any way to get some kind of list of potential causes of such a crash based on experience?
Things like 'check segue spelling' and 'do not perform segues in ViewDidLoad' have already been ruled out.
I feel that checklists are a good way for novices like me to learn about pitfalls in coding but if it's impossible to answer or too many answers then let me know and I'll kill the question.
Thanks.
Upvotes: 1
Views: 1028
Reputation: 899
Ok so after looking high and low for errors in classes, delegates etc it turns out it's an error in Swift/XCode itself.
The culprit is simply the TextView on the page which needs to have its default text set to blank in order for the page to load. Any default text needs to be set in the viewDidLoad instead.
The full solution is contained here - iOS 9 Segue Causes App To Freeze (no crash or error thrown)
It would still be good to know if there is any way to see a log of errors thrown during view init but in this case it all comes down to an insignificant element on the view.
Upvotes: 0
Reputation: 2241
Checklists can be fixed by implementing protocols.. Check the WWDC following:
https://developer.apple.com/videos/play/wwdc2015-408/
Furthermore, in regards to segues, there's a few things to note (the same applies to OSX)...
Note:
i) A segue, per definition is a transition between one one part to another (of a scene in a film or a part in music). So they're meant to be a "go-between" when it comes to view controllers...
i.e. ViewController1 <-- segue ->> ViewController2
ii) When you subclass and override prepareForSegue
you're telling your code that you want to handle the transition yourself. i.e. in a UITabviewController (or NSStabViewController), you override their default behaviours with some you want to implement of your own in the overrides
Part 1) PrepareForSegue
- Before it happens:
This is where you instantiate, configure, set up etc... your view-controllers.. If they're already set-up then you should otherwise be super-calling here.
//i.e. super.PrepareSegueForIdentifier(identifier)
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "something" {
// Do your thing here
// MARK: IFYES
} else {
prepareForSegue(segue, sender: sender)
}
}
If you have pre-preparation work for your "to be" view controller, then set it up in the first part of the "if" statement which I marked 'IFYES'. You set up things like the animations, from and to colors, sizes etc...
After this has been done, then there's another method:
performSegueWithIdentifier:
And an example I use is:
override func performSegueWithIdentifier(identifier: String, sender: AnyObject?) {
if (identifier == "yourIdentifier") {
Do something here
} else {
super.performSegueWithIdentifier(identifier, sender: sender)
}
}
This is when the segue, with the identifier of yourIdentifier
actually does something. i.e. when your viewController calls in an action or function :
func someFunction(){
self.performSegueWithIdentifier("yourIdentifier", sender: senderObjectName)
}
This is of course if you've made sure that your segue's between controllers etc... have the correct identifiers and types...
Upvotes: 3