Hi I am trying to add a stepper to my app but got this error:

ViewController.h:

@interface ViewController : UIViewController {    
      IBOutlet UILabel *NrOfQuestLabel;}
-(IBAction)NrofQuestChange:(UIStepper *)sender;

ViewController.m:

-(IBAction)NrofQuestChange:(UIStepper *)sender:{ double value = [sender value];
[NrOfQuestLabel setText: [NSString stringWithFormat:@"%d", (int)value]];
 }

Error in .m: !Expected identifier !"sender" used as the name of the previous parameter rather than as part of the selector

Any help?

有帮助吗?

解决方案

Unless its another typo, you have an extra colon in xour code right after sender:

-(IBAction)NrofQuestChange:(UIStepper *)sender:{ 
    double value = [sender value];
    [NrOfQuestLabel setText: [NSString stringWithFormat:@"%d", (int)value]];
 }

should be

-(IBAction)NrofQuestChange:(UIStepper *)sender{
    double value = [sender value];
    [NrOfQuestLabel setText: [NSString stringWithFormat:@"%d", (int)value]];
 }

Thats why the compiler can't decide whether sender is a variable or part of the method name.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top