2014-03-03 42 views
0

我有一個觸發方法的按鈕。此方法顯示圖像(由計時器隔開),並在顯示一定數量的圖像後停止。因此,按鈕需要在按下後才能隱藏,因此無法再次按下該按鈕並跳過無限循環。我會接受任何用於實現這一目標的技術,而不是完全摧毀效率。其觸發方法正在運行時隱藏按鈕

這裏是我的嘗試:

-(IBAction)spinButton:(id)sender { 
//hide spin button after press 
spinButton.hidden = YES; 
// The count starts at 0, so initialize "count" to 0. 
count = 0; 
// Use an NSTimer to call displayPic: repeatedly every 1 second ("repeats" is set to "YES") 
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(displayPic:) userInfo:nil repeats:YES]; 
//show button after method has fully executed 
spinButton.hidden = NO; 

我不能讓按鈕使用上面提供我的代碼消失。注意:如果我省略了最後一行(spinButton.hidden = NO;),按鈕在第一次按下時不再出現,並且不再出現。

+0

什麼再次顯示按鈕,當你停止計時器(顯示一個特定數量的圖像後) ? – Hejazi

回答

2

你不應該只是移動到displayPic(裏面的如果檢查次數是夠高?)

+0

這是我第一次嘗試。我回去檢查我是否第一次犯了錯誤,並發現我的spinButton.hidden = NO在我的if語句中跟隨了我的invalidate計時器。我切換順序,它完美無瑕!有時你需要另一雙眼睛。謝謝 – meisenman

+0

我知道這個感覺很好,不客氣! – mackworth

0

您正在隱藏該按鈕並再次取消隱藏。該視圖不會在兩者之間更新,即使該方法會在幾毫秒內執行,因此您無法看到它。您可能想要將最後一行移至另一個方法,例如你的displayPic:方法。