开发者

how to set timer to awake method in iPhone?

开发者 https://www.devze.com 2023-03-03 14:24 出处:网络
I have an -(IBAction)get; its functionality is to awake some methods. -(IBAction)get{ [self msgToServer:@\"MSRQ\" Username:username];

I have an -(IBAction)get; its functionality is to awake some methods.

-(IBAction)get{
    [self msgToServer:@"MSRQ" Username:username];
        [self msgToServer:@"TRNR" Username:username];
        [self subscriptonList];
}

now i want to know that how can i set a timer in it? when user press "get" button it should call only [self msgToServer:@"MSRQ" Username:username]; & after 5 seconds it should awake [self msgToServer:@"TR开发者_运维技巧NR" Username:username]; and after next 5 seconds it should awake [self subscriptonList]; automatically.

i Hop question is understandable. Note: I am working in Xcode, Objective-c Thanx in advance


You can make use of

[invocation performSelector:@selector(invokeMethod) withObject:object afterDelay:delay];

Or if you want a timer

[NSTimer scheduledTimerWithTimeInterval:inteval target:self selector:@selector(urMethod) userInfo:nil repeats:YES/NO];

If you want to use dummy methods

-(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];

}
0

精彩评论

暂无评论...
验证码 换一张
取 消