【问题标题】:Objective c: passing an NSTimer with a button目标 c:通过按钮传递 NSTimer
【发布时间】:2011-01-25 18:12:29
【问题描述】:

如何将我声明为计时器的 NSTimer 传递给按钮调用的方法?

[stickfig addtarget:self action:@selector(tapfig:andtime:) forcontrolevents:uicontroleventtouchupinside];

对格式问题感到抱歉。我不得不在我的手机上问这个。

【问题讨论】:

    标签: objective-c timer uibutton


    【解决方案1】:

    你不能操作:只会发送按钮本身。在类中,您可能希望将值存储在 NSDictionary 中。您可以标记按钮并将标记用作字典键的 NSNumber。

    例如

    ...
    //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]];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多