@objc(SEPushNoAnimationSegue)
class SEPushNoAnimationSegue: UIStoryboardSegue {
override func perform () {
self.sourceViewController.navigationController.pushViewController(self.destinationViewController, animated:false)
}
}
In the above code, I have 2 questions: 1). it has a compile error: 'UINavigationController!' does not have a member named 'pushViewController'
But in that class, it did has a pushViewController method.
2). I have to add the annotation: @objc(SEPushNoAnimationSegue), otherwise, in storyboard, it only recognize the random generated name, like, _tcxxxxSEPushNoAnimationSegue.
why these 2 issues happen here?
Well, in addition to that, Ctrl+dragging also helps set up segues. So, Ctrl+Drag from the “Go to Other View Controller” button, to somewhere in the second View Controller. It can be anywhere in the main box of the second view controller. When you release, it will show you a box like the one below.
Assigning an identifier for the segue:Select the segue, from the attribute inspector you'll see "Identifier" text field, that's it! make sure to insert the exact same name that used in performSegueWithIdentifier .
Relationships segues are different from the other segues in that they are resolved at build time. When a UITabBarController is loaded from a storyboard, all of its constituent view controllers are already 'inside' of it in the same NIB that represents the scene with the tab bar controller.
UIStoryboardSegue has an irritating flaw: its sourceViewController and destinationViewController properties are typed as AnyObject!
(that's the case even in Objective-C (Id type)) and not as UIViewController
, as it should be.
That same flaw creates havoc in your perfect and simple code. Here's how to rewrite it in order to fix the compile errors:
@objc(SEPushNoAnimationSegue)
class SEPushNoAnimationSegue: UIStoryboardSegue {
override func perform () {
let src = self.sourceViewController as UIViewController
let dst = self.destinationViewController as UIViewController
src.navigationController.pushViewController(dst, animated:false)
}
}
NOTE: Apple fixed this thing in iOS 9. sourceViewController
and destinationViewController
are now correctly declared as UIViewController
.
The Swift compiler stores its symbols using its own name mangling, and good ol' Objective-C does not recognize it in Xcode. Using an explicit @obj()
solves the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With