我有-(IBAction)get;
它的功能是唤醒一些方法。
-(IBAction)get{
[self msgToServer:@"MSRQ" Username:username];
[self msgToServer:@"TRNR" Username:username];
[self subscriptonList];
}
现在我想知道如何在其中设置计时器?当用户按“获取”按钮时,它应仅呼叫[self msgToServer:@"MSRQ" Username:username];
& 5秒后它应该唤醒[self msgToServer:@"TRNR" Username:username];
,在接下来的5秒后它应该自动唤醒[self subscriptonList];
。
答案 0 :(得分:2)
您可以使用
[invocation performSelector:@selector(invokeMethod) withObject:object afterDelay:delay];
或者如果你想要一个计时器
[NSTimer scheduledTimerWithTimeInterval:inteval target:self selector:@selector(urMethod) userInfo:nil repeats:YES/NO];
如果你想使用虚拟方法
-(IBAction)get{
[self msgToServer:@"MSRQ" Username:username];
[self performSelector:@selector(sendMessage) withObject:nil afterDelay:5];
}
- (void)sendMessage
{
[self msgToServer:@"TRNR" Username:username];
[self performSelector:@selector(subscriptonList) withObject:nil afterDelay:5];
}