why do I get this warning in my code below:
- (IBAction)shareThisActionSheet:(id)sender
{
int row = [sender tag]; //warning is here! Multiple methods named 'tag' found
...
Description
The problem is that the compiler sees more than one method named tag
in the current translation unit, and these declarations have different return types. One is likely to be -[UIView tag]
, which returns an NSInteger
. But it's also seen another declaration of tag
, perhaps:
@interface MONDate
- (NSString *)tag;
@end
then the compiler sees an ambiguity - is sender
a UIView
? or is it a MONDate
?
The compiler's warning you that it has to guess what sender
's type is. That's really asking for undefined behavior.
Resolution
If you know the parameter's type, then specify it:
- (IBAction)shareThisActionSheet:(id)sender
{
UIView * senderView = sender;
int row = [senderView tag];
...
else, use something such as an isKindOfClass:
condition to determine the type to declare the variable as before messaging it. as other answers show, you could also typecast.
The problem is that sender
is defined as a (id)
object. At compile time xcode does not know what kind of objects will get passed to your function.
If you write this function for a specific object type, you could you could write for example
- (IBAction)shareThisActionSheet:(UIButton*)sender
or you could hint the compiler the type of object with the call
int row = [(UIButton*)sender tag];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With