iOS Warning: Semantic Issue (Multiple methods named 'setDelegate:' found)
-
14-11-2019 - |
题
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...
解决方案
It should be sufficient to cast the view controller to the known type:
[(SettingsViewController *)[segue destinationViewController] setDelegate:self];