自动消防IBAction

时间:2013-03-10 17:07:37

标签: objective-c xcode cocoa-touch ibaction

我有一个按钮,想要自动触发它而不需要触摸。 有可能吗?

-(IBAction)xxx:(id)sender 

3 个答案:

答案 0 :(得分:3)

我的回答假设你有方法:

- (IBAction)someAction:(UIButton *)sender {
}

并且您在名为someButton的实例变量中引用了该按钮。

如果您现在只需要“解雇”,只需拨打电话:

[self someAction:someButton];

如果你需要“开火”一次,但稍后,你可以这样做:

// call it 5 seconds from now
[self performSelector:@selector(someAction:) withObject:someButton afterDelay:5.0];

如果要反复触发,请使用计时器:

myTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(buttonTimerFired) userInfo:nil repeats:YES];

- (void)buttonTimerFired {
    [self someAction:someButton];
}

答案 1 :(得分:2)

可以像每个常规函数一样调用Action - 您可以通过在其他东西上运行计时器来执行此操作。

答案 2 :(得分:0)

您应该使用NSTimer来完成工作。

[NSTimer scheduledTimerWithTimeInterval: 0.01f target: self selector: @selector(BtoonMethod) userInfo: nil repeats: NO];

-(void)BtoonMethod
{
  // write code for call yor button method

}
相关问题