Objective-C 中的递增和递减函数错误

Increment and Decrement function bugs in Objective-C

我几周前开始学习 Objective-C。在创建 "Add to Cart" 函数之前,我没有问题。在 "Add to Cart" 函数中,我有 2 个按钮,一个加号按钮和一个减号按钮。加号按钮用于将值增加 1,减号按钮用于将值减 1。它看起来像这样:

问题是加号按钮在 9 时停止增加值。所以在值为 9 之后,如果我单击加号按钮,值变为 1。如果我再次单击加号按钮,它变为 11 .如果我再次点击,它变成1.如果我再次点击,加号按钮不再增加价值。日志正确显示值,但没有 UI。这是日志:

这是我的代码:

#import "ThirdViewController.h"

@interface ThirdViewController ()

@end

@implementation ThirdViewController

-(void)viewWillAppear{
    self.i = 0;
}

- (IBAction)plusBtn:(UIButton *)sender {
    self.i++;
    [_txtNumber setText:[NSString stringWithFormat:@"%d",self.i]];
    NSLog(@"%d",self.i);
}

- (IBAction)minusBtn:(UIButton *)sender {
    --self.i;
    [_txtNumber setText:[NSString stringWithFormat:@"%d",self.i]];
    NSLog(@"Minus");
}

- (IBAction)addToCartBtn:(UIButton *)sender {
    NSLog(@"Add");
}
@end

使标签变宽。很明显,问题出在UI