点击按钮后的一段时间后执行某些操作 [英] Do something after a certain time after button clicked

查看:142
本文介绍了点击按钮后的一段时间后执行某些操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在点击按钮后的一段时间后从视图中消失一个对象。我对如何让对象在敲击之后做某些事情感到困惑。我不确定我是否应该使用运行循环 NSTimer ,即使我知道该使用什么我仍然在点击按钮后的某个时间,如何做某事会让人感到困惑。我是iOS开发的新手,所以请光临我。

I am trying to have an object disappear from the view after a certain time after a button is tapped. I'm a little confused with how to get the object to do something a certain after its tapped. I am not sure if I should use a run loop or NSTimer, and even if I know what to use Im still confused on what to do to make something happen a certain time after the button is tapped. Im new to iOS development so please bare with me.

谢谢。

推荐答案

在按下按钮的方法中,您可以使用:

In your button pressed method you can use:

[self performSelector:@selector(myMethod) withObject:nil afterDelay:3];

并使用您想要运行的逻辑声明方法:

And declare method with logic you want to run:

-(void) myMethod
{
    //TODO: your logic goes here
}

如果需要,你甚至可以将参数传递给你的方法(withObject参数)。

You can even pass parameter to your method if you want (withObject argument).

这篇关于点击按钮后的一段时间后执行某些操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆