0
-(void)manageNetConnection{
    static BOOL closing=FALSE;
    NSLog(@"connecting Imap after net");
    if([imapStoreObj isStoreConnected] && closing==FALSE){
        [imapStoreObj close];
        NSLog(@"close store");
        closing=TRUE;
        [self performSelector:@selector(manageNetConnection) withObject:nil afterDelay:5.0];

        return;
    }else if ([imapStoreObj isStoreConnected] && closing==TRUE) {
        [self performSelector:@selector(manageNetConnection) withObject:nil afterDelay:5.0];

        return;
    }
    closing=FALSE;
    [indicatorForGetMail setHidden:NO];
    [indicatorForGetMail startAnimation:nil];
    netOff=2;
    NSLog(@"netOff==%d",netOff);

    [editFolderTable setAllowsMultipleSelection:NO];
    NSLog(@"connect net");

    [self reconnect];


}

在重新建立连接之前,预计此函数会调用自身。问题是该函数在指定的延迟后不会调用自己。请帮忙

4

2 回答 2

0

我在@performSelector 上遇到了同样的问题。请改用 @performSelectorOnMainThread 和 NSTimer。

-(void)manageNetConnection{
    ...
    [self performSelectorOnMainThread:@selector(startTimer:) withObject:@"manageNetConnection" waitUntilDone:YES];
    ...
}

- (void)startTimer:(NSString *)data{
    [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(endTimer:) userInfo:data repeats:NO];
}

- (void)endTimer:(NSTimer *)timer{
    NSString *target = [timer userInfo];
    SEL targetSelector = NSSelectorFromString(target);
    [self performSelectorInBackground:targetSelector withObject:nil];
}
于 2012-09-07T10:58:41.983 回答
0

Below line will call -(void)manageNetConnection; method for once after 5.0 if your both conditions are satisfying.

[self performSelector:@selector(manageNetConnection) withObject:nil afterDelay:5.0];

Check for both if condition and else if condition satisfies.

if([imapStoreObj isStoreConnected] && closing==FALSE){

        [self performSelector:@selector(manageNetConnection) withObject:nil afterDelay:5.0];

        return;
    }else if ([imapStoreObj isStoreConnected] && closing==TRUE) {
        [self performSelector:@selector(manageNetConnection) withObject:nil afterDelay:5.0];

        return;
    }

or else you can use which repeats the call

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(testMethod:) userInfo:nil repeats:YES];
于 2012-09-07T11:00:58.190 回答