我不能使用UIStepper从UITextfield获取值来增加或减少stepper.value请帮我解决这个问题。 我的代码:
-(void)stprPressd:(id)sender
{
float a=[textField.text floatvalue]
[stepper setMinimumValue:0];
[stepper setContinues:YES];
[stepper setWraps:YES];
[stepper setStepValue:1]
textField.text=[NSString stringWithFormat@"%f",stepper.value]
stepper.value=a;
stepper setMaximumValue:10];
}
答案 0 :(得分:0)
我认为您在更改事件中设置控件属性。您应该初始化控件属性并将其设置为viewDidLoad
方法。
- (void)viewDidLoad {
[super viewDidLoad];
// Frame defines location, size values are ignored
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(120, 20, 0, 0)];
// Set action target and action for a particular value changed event
[stepper addTarget:self action:@selector(stepperPressed:) forControlEvents:UIControlEventValueChanged];
[stepper setMinimumValue:0];
[stepper setMaximumValue:10];
[stepper setContinues:YES];
[stepper setWraps:YES];
[stepper setStepValue:1]
[self.view addSubview:stepper];
[stepper release];
}
您的stepperPressed:
方法应如下所示
-(void)stepperPressed:(UIStepper *)sender{
textField.text=[NSString stringWithFormat@"%lf",sender.value]
}