我有一个按钮,想要自动触发它而不需要触摸。有可能吗?
-(IBAction)xxx:(id)sender 发布于 2013-03-11 01:56:45
我的回答是假设你有这个方法:
- (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];
}发布于 2013-03-11 01:10:37
Action可以像调用每个常规函数一样调用--您可以通过在其他函数上运行计时器来实现。
发布于 2013-03-11 01:11:45
你应该使用NSTimer来完成你的工作。
[NSTimer scheduledTimerWithTimeInterval: 0.01f target: self selector: @selector(BtoonMethod) userInfo: nil repeats: NO];
-(void)BtoonMethod
{
// write code for call yor button method
}https://stackoverflow.com/questions/15325018
复制相似问题