0

我目前正在使用以下代码为视图之间的转换设置动画,并且当在此refreshTheServers过程中调用该方法时,整个应用程序会冻结,刷新服务器,然后显示视图。

我怎样才能使它成为一个无缝的过程,其中视图加载然后服务器被刷新?

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:NO];
[self.view addSubview:self.folderView];
[UIView commitAnimations];
[self refreshTheServers];

编辑:这是我的 refreshTheServers 方法的代码:

- (void)refreshTheServers {

KeychainItemWrapper* keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"KeychainTest" accessGroup:nil];

NSString *userForConnect = [NSString stringWithFormat:@"%@", [keychain objectForKey:(__bridge id)(kSecAttrAccount)]];
NSString *passForConnect = [NSString stringWithFormat:@"%@", [keychain objectForKey:(__bridge id)(kSecValueData)]];



CTCoreAccount *account = [[CTCoreAccount alloc] init];

dispatch_queue_t taskQ = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_async(taskQ, ^{
    [account connectToServer:[[NSUserDefaults standardUserDefaults]
                              stringForKey:@"server"]
                        port:993
              connectionType:CTConnectionTypeTLS
                    authType:CTImapAuthTypePlain
                       login:userForConnect
                    password:passForConnect];

    dispatch_async(dispatch_get_main_queue(), ^{
        // ... the thread is over, do stuff on the main thread ...

        CTCoreFolder *inbox = [account folderWithPath:theAppDelegate.folder];

        NSArray *inboxMessages = [inbox messagesFromUID:1 to:0 withFetchAttributes:CTFetchAttrEnvelope];

        [[self allMessages] removeAllObjects];
        [[self allMessages] addObjectsFromArray:inboxMessages];

        [self.messagesTable reloadData];
    });
});
}

我究竟做错了什么?

4

1 回答 1

0

以下调用是同步的:[inbox messagesFromUID:1 to:0 withFetchAttributes:CTFetchAttrEnvelope]; 这就是应用程序冻结的原因。Instruments CPU 采样器可以突出这一点。

于 2013-04-28T23:15:58.817 回答