Several methods were found named 'tag'

why I get this warning in my code below:

- (IBAction)shareThisActionSheet:(id)sender
{
    int row = [sender tag]; //warning is here! Multiple methods named 'tag' found
    ...
+5
source share
3 answers

Description

The problem is that the compiler sees more than one method with a name tagin the current translation unit, and these declarations have different types of returned data. Most likely there will be -[UIView tag]one that returns NSInteger. But he also saw another ad tag, perhaps:

@interface MONDate
- (NSString *)tag;
@end

then the compiler sees ambiguity - is that sendera UIView? or is it MONDate?

The compiler warns you that it must guess what the type is sender. It really requires undefined behavior.

Resolution

, :

- (IBAction)shareThisActionSheet:(id)sender
{
 UIView * senderView = sender;
 int row = [senderView tag];
 ...

else, - isKindOfClass:, , . , .

+12

, sender (id). xcode , .

, , ,

- (IBAction)shareThisActionSheet:(UIButton*)sender

int row = [(UIButton*)sender tag]; 
+3

, ​​:

UIButton * button = (UIButton *)sender;
int row = button.tag;
+2

All Articles