我正在嘗試使用UIStepper
來遞增或遞減整數, 但「 - 」和「+」都會增加整數!我怎樣才能識別「+」和「 - 」按鈕?如何使用UIStepper
在UIStepper
頭文件中有兩個UIButton
S:
UIButton *_plusButton;
UIButton *_minusButton;
例如:
- (IBAction)changeValue:(id)sender
{
UIStepper *stepper = (UIStepper *) sender;
stepper.maximumValue = 10;
stepper.minimumValue = 0;
if (stepper)
{
integer++;
[label setText:[NSString stringWithFormat:@"%d",integer]];
}
else
{
integer--;
[label setText:[NSString stringWithFormat:@"%d",integer]];
}
}
感謝,但我有這個錯誤: '多個方法名爲'value'found'和'Initializing'double'帶有不兼容的表達式pe'NSString *'' –
@ Mc.Lover確保變量是正確輸入或鑄造的。你需要確定它是明確的'UIStepper *'。將它聲明爲'id'是導致警告的原因。 –
如果您確定發件人始終是UIStepper,您可以執行此操作[(UIStepper *)發件人值]。 –