0

UIViewController我有一些代码在委托中显示两个。

根视图控制器.m

request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"***some https url here ***"]];
// custom implementation of NSURLConnectionDelegate
dataman = [[DataManager alloc] initWithParentcontroller:self]; 
mainConn = [[NSURLConnection alloc] initWithRequest:request delegate:dataman]; 

在 AuthenticationViewController.h

@protocol ShowAuthenticationWindowDelegate <NSObject>
@required
- (void) onFinishedEnteringCredentials:(NSURLCredential*)credentials;
- (void) onCancelAuthentication;
@end

在 AuthenticationViewController.m

- (IBAction) onClickLogin:(id)sender;
{
    ....
    // authDelegate => id <ShowAuthenticationWindowDelegate>
    [authDelegate onFinishedEnteringCredentials:credentials];
    [self dismissModalViewControllerAnimated:YES];
    ....
}

在 DataManger.h(DataManager 类)中实现NSURLConnectionDelegateand ShowAuthenticationWindowDelegate

在 Datamanager.m 在didReceiveAuthenticationChallenge委托函数中,我将其显示AuthentiationViewController为模式对话框以收集用户名/密码。

-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
    AuthenticationViewController *authview = [[AuthenticationViewController alloc] initWithNibName:@"AuthenticationViewController" bundle:[NSBundle mainBundle]];
    authview.modalPresentationStyle = UIModalPresentationFullScreen;
    authview.modalTransitionStyle   = UIModalTransitionStyleFlipHorizontal;
    authview.credentialsDelegate = self;
    [rootController presentModalViewController:authview animated:YES];
} 

这里我展示了UIViewController一个视图中的活动指示器。在我AuthenticationViewController通过调用关闭登录按钮事件处理程序之一中的前一个对话框后,我以模态方式显示它dismissModalViewController。在发送带有质询对象(以前缓存)的凭据后,我以模态方式显示 ActivityViewController,但无论我做什么都不会显示。我试图展示一个UIAlertView可行的方法,但没有显示我的 activityviewcontroller。我检查了参数和对象,一切都有效。连代表都接电了!!!所有代码都被调用,但未显示对话框。

可能是我错过了什么吗???

- (void) onFinishedEnteringCredentials:(NSURLCredential*)credentials;
{

    [[authChallenge sender] useCredential:credentials forAuthenticationChallenge:authChallenge];
    // create an activity modal dialog 
    if (activityController == nil) {
        activityController = [[ActivityViewController alloc] initWithNibName:@"ActivityViewController" bundle:[NSBundle mainBundle]];
        activityController.modalPresentationStyle = UIModalPresentationFullScreen;
        activityController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    }
    [rootController presentModalViewController:activityController animated:YES];
}
4

1 回答 1

0

我已经找到了解决方案,如果有人想背靠背显示两个模态对话框,您应该在正在关闭的控制器上将“动画”参数设置为“否”。下一个控制器使用“presentViewController”功能显示时,动画转换似乎尚未完成。

于 2012-05-19T23:18:07.373 回答