C_Dub
C_Dub

Reputation: 77

How to cast to my UIViewController

I'm tearing my hair out on this one. I have a menu view that has 2 buttons. Each button has been routed to another view controller via separate segue identifiers. That is, they both point to the same view controller, but under different segues.

My research all over indicates that I need to 'cast' to my destination view controller, and I cannot for the life of me find code that works, nor, perhaps more perplexing, WHERE to put that code.

These are the properties in my DESTINATION / TankCalculatorViewController view controller header file:

// Properties for segue identifiers
@property(nonatomic, readonly) NSString *tankCalcOne;
@property(nonatomic, readonly) NSString *tankCalcTwo;

This code is in my MENU implementation file:

// This allows the view for tankCalcOne or Two depending on which button is clicked in the menu

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    //cast???

    if ([segue.identifier isEqualToString:@"tankCalcOne"])
    {
        [[segue destinationViewController] TankCalculatorViewController:self];
    }
    else ([segue.identifier isEqualToString:@"tankCalcTwo"]);
    {
    [[segue destinationViewController] TankCalculatorViewController:self];
    }
 }

I have seen dozens of answers here saying things like, "You need to cast to your custom class," but none of the code examples I have seen exactly apply to what I am doing, and I have no idea where to put said code. I am guessing it would go in the header for the destination view controller, and then I would import TankCalculatorViewController.h into my menu implementation, but that's really a shot in the dark. I have been taking a crash course in this world, and even after a few months working with this language, some of the concepts and certainly the nomenclature is still sinking in. Any help would be greatly appreciated.

If it helps, I am getting the following error in my if/then:

'No known instance instance method for selector TankCalculatorViewController'

Thanks in advance.

Upvotes: 0

Views: 1914

Answers (2)

Retro
Retro

Reputation: 4005

I have been doing like this

if ([[segue identifier] isEqualToString:@"InvoiceDetail"])
{
    IVInvoiceDetailViewController *detailViewController = [segue destinationViewController];
    detailViewController.yourString = self.yourStringObject;
}

Upvotes: 0

codercat
codercat

Reputation: 23301

it simple do as c concept like

[(MyControllerClassName *)[segue destinationViewController]TankCalculatorViewController:self]];

Upvotes: 1

Related Questions