0

I'm new to iOS 5 and having an issue with delegates and segues.

I have a main view controller that segues to a SettingsViewController. I make the main VC the delegate of the Settings VC with this code:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"SETTINGS"]) {
        [[segue destinationViewController] setDelegate:self];
    }
}

The SettingViewController then segues to multiple option screens. I was trying to make the SettingsViewController the delegate for those option screens, but I get the warning that the setDelegate: method was found in two places (the MainViewController, and the SettingsViewController).

How best to resolve this issue? Thanks!

P.S. I've discovered I only get this warning when I enable Strict Selector Matching warnings in the compiler settings (on the advice of a tutorial book). Leave it off? Fix the problem? I'm not really sure...

2
  • Leave that warning off. It's not helpful. If you really want it on, you can suppress the warning by casting the results of [segue destinationViewController] to the appropriate type. Jan 27, 2012 at 0:12
  • Thanks, Kevin. Can you give me an example of casting? I've heard the term but am not quite sure what it would look like. Jan 27, 2012 at 16:59

1 Answer 1

0

It should be sufficient to cast the view controller to the known type:

[(SettingsViewController *)[segue destinationViewController] setDelegate:self];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.