0
如何將一個NSTimer作爲定時器聲明爲一個被按鈕調用的方法?目標c:通過一個按鈕傳遞一個NSTimer
[stickfig addtarget:self action:@selector(tapfig:andtime :) forcontrolevents:uicontroleventtouchupinside];
對不起格式化。我不得不在手機上問這個問題。
如何將一個NSTimer作爲定時器聲明爲一個被按鈕調用的方法?目標c:通過一個按鈕傳遞一個NSTimer
[stickfig addtarget:self action:@selector(tapfig:andtime :) forcontrolevents:uicontroleventtouchupinside];
對不起格式化。我不得不在手機上問這個問題。
你不能行動:只會發送按鈕本身。在類內部,你可能想要將值存儲在一個NSDictionary中。您可以標記按鈕並將標記用作字典鍵的NSNumber。
Ex。
...
//Tag buttons
button1.tag = 1;
button2.tag = 2;
button3.tag = 3;
//Add timers to dictionary
[mutableDictionary setObject:button1Timer forKey:[NSNumber numberWithInt:button1.tag]];
...
//Action for buttons
-(void)tapfig:(id)sender
{
NSTimer *timer = [mutableDictionary objectForKey:[NSNumber numberWithInt:((UIButton*)sender).tag]];
}