IOS超时的另一种做法

来源:互联网 发布:数据呈现 编辑:程序博客网 时间:2024/05/17 02:10

超时可以用NSTimer,但还可以用下面这种方法


在开始后,调用

    [self performSelector:@selector(pingTimeOut) withObject:nil afterDelay:self.timeout];


当有返回后,调用这句代码,取消延迟执行方法的调用

    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(pingTimeOut) object:nil];


如果没有返回,就会调用pingTimeOut方法,进入超时

0 0