ClassCastException for segue


Trying to create a transition from one view controller to another, I’ve created a Segue. It’s working, however if I want to pass some data to new ViewController:

public void prepareForSegueSender(UIStoryboardSegue segue, @Mapped(ObjCObjectMapper.class) Object sender) {
    super.prepareForSegueSender(segue, sender);
    if (segue.identifier().equals("second_view_segue")) {
        SecondViewController secondViewController = (SecondViewController) segue.destinationViewController();

Unfortunately I get an error:

Terminating app due to uncaught exception 'java.lang.ClassCastException', reason: 'java.lang.ClassCastException: apple.uikit.UIViewController cannot be cast to com.myCompany.ios.ui.SecondViewController

I would be grateful for any advice.

Dear Mateusz Bartos,

please make sure the @RegisterOnStartup annotation is present on the com.myCompany.ios.ui.SecondViewController class.

Best Regards,

1 Like

Dear Kristóf,

It was missing, now it’s working correctly. Thank you for your answer!