2017-06-29 21 views
-3

我一直在寻找解决方案来解决我的问题,但是我发现所有的东西都是“定时器”, 我需要在文本框中以升序显示价格。 我该怎么做?在iOS中倒计时Objective-C

回答

2

你的问题有点不清楚。你希望倒数,但是按升序排列? 您是否意思是随着时间流逝或增加价值而增加价值?

我已经写了一些代码来帮助你,不管你的需求是什么。

@interface ViewController() 
@property (strong, nonatomic) IBOutlet UITextField *textField; 
@property int price; 
@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    _price = 1000; 
    [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(updatePrice) userInfo:nil repeats:YES]; 

} 


- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 
-(void)updatePrice 
{ 
    _price = _price-10; // Here I'm reducing the price by 10, add to increase the price 

    dispatch_async(dispatch_get_main_queue(), ^{ 
     [_textField setText:[NSString stringWithFormat:@"%ld",_price]]; 
    }); 
}