Question

I have 1 View Controller and 1 Tab Bar Controller with 2 Navegation Controller.

In my simple View I have one form and then when I click in button "Login" I want to load the first View in my Tab Bar Controller.

With this code works perfect:

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    Inicial *telaInicial = [storyboard instantiateViewControllerWithIdentifier:@"tabBar"];
    [self presentViewController:telaInicial animated:YES completion:nil];

But I want to send and value to this View "Inicial" and I put this:

telaInicial.email = email.text;

But I got this error message:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarController setEmail:]: unrecognized selector sent to instance 0x9fdc8f0'

enter image description here

Était-ce utile?

La solution

The object telaInicial that you think is an instance of Inicial is actually a UITabBarController therefore you cannot set the email property on it as it doesn't exist.

I think you want something like this...

UITabBarController *tabBarController = [self.storyboard instantiateViewControllerWithIdentifier:@"tabBar"];

UINavigationController *navController = tabBarController.viewControllers[0];

Inicial *telaInicial = navController.topViewController;

telaInicial.email = // blah

Autres conseils

It means that there isn't a setEmail method for the telaInicial object. Is that an instance of a subclass you've written? If so, you might be getting the error because you haven't written a setEmail method for it or because you haven't declared the instance variable email as an @property, in which case the setter and getter methods for it would be synthesized automatically by XCode (prior to XCode 4.something, I think you need to synthesize your properties explicitly - after that version, they're automatic).

Try to write class, that will store your data. You can access to it from AppDelegate (not really good solution, but very fast).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top