好的,我知道有很多这样的问题,因为我已经查看并尝试了一些解决方案。但是,我尝试过的许多方法都不起作用,或者答案太过分了,我无法真正掌握 - 我是一名新开发人员,这是我的第一个应用程序。我通过学习此时不该做什么来学习。
我在 UIStepper stepperValueChanged 设置上有“无法识别的选择器发送到实例错误”。这是给我的错误消息的内容:
[DetailViewController stepperValueChanged]: unrecognized selector sent to instance 0x8637630
我可能会为此被撕裂,但我无法真正理解这里发生了什么——到目前为止,我唯一的猜测是假设它与我的代码中存在 stepperValueChanged 的唯一点有关——在 DetailViewController.h 下,如下所示:
@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
有什么想法吗?我没有太多的线索,如果有人能在解决这个问题时帮助我解释这里到底在做什么,我将不胜感激。
如果您需要实现文件的内容,请告诉我;我会编辑进去。
.m 文件的相关区域:
@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;
}