0
votes

Feeling a little confused. I am trying to pass a NSString as an argument to this method

-(void) setRightLabelText:(NSString *)text { rightLabel.text = text; }

The code i use to call the method

for(int index=0; index<5; index++)
{
    NSNumber *num = [card.statsArray objectAtIndex:index];

    StatView *statView = (StatView *)[self.frontView viewWithTag:10+index];
    NSString *nameHolder = @"test";
    [statView setRightLabelText:nameHolder];
}

The code I used to create the View :

for(int i=0; i<totalButtons; i++) 
{       
    StatView *sv = [[StatView alloc] initWithYPos:ypos];
    sv.tag = 100 + i;
    [sv.overlayButton addTarget:self action:@selector(statTapped:)  
            forControlEvents:UIControlEventTouchUpInside];
    sv.overlayButton.tag = 10 + i;
    [self.frontView addSubview:sv];
    ypos += 26;
}

This to me looks perfect, but i get a crash when I get to this method call in the app. Error Msg : -[UIButton setRightLabelText:]: unrecognized selector sent to instance 0x5d116e0 2010-09-13 11:39:44.761 LeinsterRugby[1387:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton setRightLabelText:]: unrecognized selector sent to instance 0x5d116e0'

3
what is rightLabel? is it a UIButton like it says in your error message?Thomas Clayson
@interface StatView : UIView { @private UILabel *leftLabel; UILabel *rightLabel;user440096

3 Answers

0
votes

StatView *statView = (StatView *)[self.frontView viewWithTag:10+index]; returns an UIButton instead of a StatView because the tag matches the one you assign to the button with sv.overlayButton.tag = 10 + i;.

0
votes

It looks as though you're sending the setRightLabelText message (selector) to an instance of UIButton rather than an object of the type that you're implementing.

Rather than:

[statView setRightLabelText:nameHolder];

Do you perhaps mean:

[self setRightLabelText:nameHolder];
0
votes

Probable reason for the crash would be

StatView *statView = (StatView *)[self.frontView viewWithTag:10+index];

Your computation to get the StatView from (10+index) is wrong. Calculate your index properly.