我目前正在使用以下代码来动画视图之间的转换,当调用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];
});
});
}
我做错了什么?
发布于 2013-04-28 15:15:58
下面的调用是同步的:收件箱消息freezes :1到:0 withFetchAttributes:CTFetchAttrEnvelope;这就是应用程序冻结的原因。仪器CPU取样器可以突出显示这一点。
https://stackoverflow.com/questions/16268748
复制