2017-06-29 43 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]]; 
    }); 
}