我试着用UIStepper来增加或减少一个整数,

UIStepper头文件中有两个UIButton:

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]];
     }

}

推荐答案

你应该忽略IVAR.他们不会帮你的.

UIStepper有一个value属性,可以通过查询来确定当前值.所以你的方法可以是:

- (IBAction)valueChanged:(UIStepper *)sender {
  double value = [sender value];

  [label setText:[NSString stringWithFormat:@"%d", (int)value]];
}

Objective-c相关问答推荐

我应该为 memcpy 和 realloc 包含什么标题?

CoreData:错误:无法在 NSManagedObject 类上调用指定的初始化程序

在哪里以及如何 __bridge

如何在for (id item in items)objective-c 循环中获取数组索引?

iOS 编译错误:CDVCommandDelegateImpl没有可见的@interface 声明 Select 器执行:

NSMutableDictionary 线程安全

启动 Finder 窗口并 Select 特定文件

改变 setContentOffset:animated: 的速度?

找不到名为ProjectName的目标

UITextView 禁用文本 Select

如何在 iPhone 上显示来自 API 的 HTML 文本?

当服务器上的图像文件更改时,我的应用程序中的 SDWebImage 缓存图像会发生什么情况?

当用户返回视图控制器时如何取消 Select uitableview 单元格

dyld:找不到符号:try 运行 iOS 应用程序时的 _NSURLAuthenticationMethodClientCertificate

self.window.rootViewController 与窗口 addSubview

HTML 内容适合 UIWebview 而无需缩小

自定义 colored颜色 我的 UIActivityIndi​​catorView

通过情节提要加载时如何初始化视图?

ARC 下的 NSString 属性应该是强的还是复制的?

UITableViewCell中的文本居中对齐问题