Okay, I know there is a ton of these questions out there, because I've looked and tried some of the solutions. However, many of the ones I tried didn't work or the answer was too over my head for me to really grasp well - I'm a new developer and this is my first app. I learn by learning what not to do at this point.

I have the 'unrecognized selector sent to instance error' on a UIStepper stepperValueChanged setup. Here is the contents of the error message as it is given to me:

[DetailViewController stepperValueChanged]: unrecognized selector sent to instance 0x8637630

I will probably be ripped apart for this, but I can't really understand what's going on here - my only guess so far is to assume it has something to do with the only point in my code where stepperValueChanged exists - under the DetailViewController.h, as placed below:

@interface DetailViewController : UIViewController <UISplitViewControllerDelegate>
{
// Create GUI parameters for text fields, text labels, and the stepper:
IBOutlet UITextField *value1;
IBOutlet UITextField *value2;
IBOutlet UITextField *value3;
IBOutlet UISwitch *double_precision;
IBOutlet UILabel *value1_type;
IBOutlet UILabel *value2_type;
IBOutlet UILabel *value3_type;
IBOutlet UILabel *deriv_units;
IBOutlet UILabel *units;
IBOutlet UILabel *result;
IBOutlet UIStepper *stepper;
}

//  Define properties of the above GUI parameters:
@property (nonatomic, retain) UITextField *value1;
@property (nonatomic, retain) UITextField *value2;
@property (nonatomic, retain) UITextField *value3;
@property (nonatomic, retain) UILabel *value1_type;
@property (nonatomic, retain) UILabel *value2_type;
@property (nonatomic, retain) UILabel *value3_type;
@property (nonatomic, retain) UILabel *deriv_units;
@property (nonatomic, retain) UILabel *units;
@property (nonatomic, retain) UILabel *result;

//  Setup property as instance of UIStepper:
@property (nonatomic, strong) IBOutlet UIStepper *stepper;

//  Setup NSString instance for segue linking:
@property (nonatomic, strong) NSString *equationName;

@property (strong, nonatomic) id detailItem;
@property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;

//  IBActions for the Calculate button and UIStepper instance:
- (IBAction)Calculate:(id)sender;
- (IBAction)stepperValueChanged:(id)sender;
- (IBAction)double_precision:(id)sender;

@end

Any ideas what is going on here? I don't have much of a clue, and if anyone can help explain to me what exactly is in play here while addressing it, I would be more than grateful.

If you need the contents of the implementation file, let me know; I'll edit it in.

Relevant areas of the .m file:

@interface DetailViewController ()

@property (strong, nonatomic) UIPopoverController *masterPopoverController;
- (void)configureView;
@end

@implementation DetailViewController

//  Synthesize an instance of NSString for segue linking:
@synthesize equationName = _equationName;;

//  Synthesize all other variables:

@synthesize value1 = _value1;
@synthesize value2 = _value2;
@synthesize value3 = _value3;
@synthesize value1_type = _value1_type;
@synthesize value2_type = _value2_type;
@synthesize value3_type = _value3_type;
@synthesize deriv_units = _deriv_units;
@synthesize result = _result;
@synthesize units = _units;
@synthesize stepper = _stepper;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
self.title = _equationName;
self.stepper.stepValue = 1;
self.stepper.autorepeat = NO;
self.stepper.continuous = YES;
self.stepper.wraps = YES;
int eqNum;
if ((_equationName = @"Energy-Frequency Relation"))
{
    eqNum = 1;
    self.stepper.minimumValue = 1;
    self.stepper.maximumValue = 3;
}
else if ((_equationName = @"Energy-Frequency-Wavelength Relation"))
{
    eqNum = 2;
    self.stepper.minimumValue = 1;
    self.stepper.maximumValue = 4;
}
 // Take _equationName quantization and use it in a switch case to determine the formula that IBAction will use:
if (dflt)
{
    switch (eqNum)
    {
        case 1:
            if ((stepper.value = 1))
            {
                // Change deriv_units appropriately:
                self.deriv_units.text = @"Energy (Joules)";
                // This is a Planck's constant calculation, we hide the second variable as the constant
                // is stored:
                self.value2.hidden = YES;
                self.value2_type.hidden = YES;
                self.value3.hidden = YES;
                self.value3_type.hidden = YES;
                // Now we set up the parameters of the first entry variable:
                self.value1_type.text = @"Frequency (in Hz)";
                double frequency = [value1.text doubleValue];
                double Planck = 6.626069e-34;
                double energy = Planck * frequency;
                // Now we set up the return field to return results:
                NSString* resultIntermediate = [NSString stringWithFormat:@"%f", energy];
                self.units.text = @"J";
            }

// Identical function statements under ViewDidLoad truncated
}


bool dflt;
-(IBAction)KeyboardGoAway:(id)sender
{
[self.value1 resignFirstResponder];
[self.value1 resignFirstResponder];
[self.value1 resignFirstResponder];
}


-(IBAction)double_precision:(id)sender
{
//  Sets double-float 'truth' value depending on state of UISwitch:
if (double_precision.on)
{
    dflt = TRUE;
}
else
{
    dflt = FALSE;
}
}

#pragma mark - Calculation runtime

-(IBAction)Calculate:(id)sender
{
//  Assigns numerical information to _equationName data -
//  switch case can only handle integer literals
//  Also handles stepper incrementation and UILabel/UITextView hiding
NSString* resultIntermediate;
self.result.text = resultIntermediate;
}
有帮助吗?

解决方案

The trailing colon makes the difference. Your action method is stepperValueChanged:, but from the error message it seems that you connected the stepper to stepperValueChanged.

其他提示

There are two reason for these kind of issues.

Probable case 1:

  • You first declared the function like - (IBAction)stepperValueChanged;
  • Connected the IBAction to stepper
  • Changed the method to - (IBAction)stepperValueChanged:(id)sender;

Solution:

Delete old connection in the interface builder and connect it again.


Probable case 2:

In your code you are calling the method using a selector where you written like: @selector(stepperValueChanged)

Solution:

Change the selector like: @selector(stepperValueChanged:)

Usually this means you are missing the method in your .m or you might of misspelled stepperValueChanged.

Edit: Actually, I believe it needs to be stepperValueChanged: with a semicolon.

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