2014-11-24 136 views
0

我想測試一個代碼來自動顯示一個按鈕,初始狀態對用戶是隱藏的。然後在40秒後出現。iOS倒計時顯示隱藏按鈕

它是一個單一的按鈕置於執行以下時,其狀態會改變爲隱藏NO

- (IBAction)done:(id)sender 
{ 
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 
} 

我想一些幫助,倒計時代碼和初始隱藏狀態的代碼導航欄。代碼將被放置在IBACtion或viewDidLoad中...

Thnx和歡呼聲!

回答

1

使用定時器像

-(void) viewDidLoad 
{ 
    [self.btnDone setHidden:true]; 
    [btnDone addTarget:self action:@selector(done) forControlEvents:UIControlEventTouchUpInside]; 

    self.timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self   selector:@selector(timerFinished) userInfo:nil repeats:NO]; 
} 
-(void)timerFinished 
{ 
    [self.btnDone setHidden:false]; 
} 

你的方法。

- (void)done 
{ 
    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 
    } 
+0

我應該創建一個btnDone屬性?將我的 - (IBAction)重命名爲btnDone? – 2014-11-25 19:38:06

+0

只需創建btnDone屬性,並且不要從設計視圖中設置iBaction。就這樣。 – 2014-11-26 04:38:56

+0

Thnx隊友!乾杯 – 2014-11-26 11:33:09