ClassCastException for segue

Hello,

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:

@Override
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();
        secondViewController.title().setText("Title");
    }
}

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,
Kristóf

1 Like

Dear Kristóf,

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