Search code examples
iosobjective-csegue

segue.destinationviewcontroller is not what expecting why?


I tried creating a segue in my project, the segue is working perfectly, but when I tried setting the value of some property it gives me an error.

unrecognised selector sent to instance 0x13fe42550

After some debugging I found that

segue.destinationViewController

is a UIViewController instead of my own controller class (MyClass)

I tried the following:

if ([segue.destinationViewController isKindOfClass:[MyClass class]]) {
    MyClass *mainViewConroller = segue.destinationViewController;
    NSInteger tagIndex = [(UILabel *)sender tag];
    mainViewConroller.id = @"65";
}

However, it's not returning an instance of the expected class name set in the class section of IB.

enter image description here


Solution

  • The usual way to distinguish multiple segues is the identifier

    if ([segue.identifier isEqualToString:@"reviewDetail"]) {
        MyClass *mainViewController = (MyClass *)segue.destinationViewController;
        NSInteger tagIndex = [(UILabel *)sender tag];
        mainViewController.id = @"65";
    }