2012-07-09 86 views
0

我在特定帧CGRectMake(40,50,400,500)中显示aNavController作为modalViewController。哪个工作正常。现在我有一个自己的按钮(viewcontroller上显示modalViewController),按下那个按钮,我需要在一个NavController上显示一些消息。但问题是当我呈现一个modalViewController。整个屏幕区域变暗/禁用。所以,无法触摸/点击自己的按钮。ModalViewController没有调光/禁用当前视图控制器

这是我的代码来呈现视图控制器。我想,我在这里错过了一些东西。请帮忙。提前致谢。

aNavController.modalPresentationStyle = UIModalPresentationFormSheet; 
anavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
[self presentModalViewController:aNavController animated:YES]; 
aNavController.view.superview.frame = CGRectMake(40,50, 400, 500); 

回答

0

最后,我能够解决与UIModalPresentationFormSheet工作方式相同的解决方法。

我添加了aNavController作为[[UIApplication sharedApplication] keyWindow]的子视图,它解决了我所有的问题。

谢谢大家的意见。

1

presentModalViewController创建一个模态对话框。当模态视图控制器启动时,用户不能在父视图上做任何事情,直到模态视图被解除。

+0

是的你是对的,用户不能在父视图上做任何事情,直到模型视图被解除。我知道那件事,在这里我想要一个解决方法。无论如何,感谢您的评论。 – 2012-07-27 05:08:54

0

问题是你正在实例化一个UIAlertViewpresentModalViewControllerUIAlertView的代理方法clickedButtonAtIndex中调用你的模态视图的同时。

像这样:

- (IBAction)clickedMyButton:(id)sender 
{ 
    UIAlertView *alertView = [[UIAlertView alloc] 
       initWithTitle: @"Title" 
       message: @"Message" 
       delegate:self 
       cancelButtonTitle:@"Close Button" 
       otherButtonTitles:@"Modal Button", @"Some Other Button", nil]; 
    [alertView show]; 
} 



- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
    if (buttonIndex == 0) { 
     NSLog(@"User Selected Cancel"); 
    } 
    else if (buttonIndex == 1) { 
     NSLog(@"Modal Button Clicked"); 
     aNavController.modalPresentationStyle = UIModalPresentationFormSheet; 
     anavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
     [self presentModalViewController:aNavController animated:YES]; 
     aNavController.view.superview.frame = CGRectMake(40,50, 400, 500); 
    }else { 
     NSLog(@"Some Other Button Clicked"); 
    } 
} 

或者,如果你想为你的UIAlertView出现在您的导航控制器的顶部,忽略上面的,只是等待打电话给你的警告,直到导航控制器- (void)viewDidAppear:(BOOL)animated方法。除非绝对必要,否则我建议你改变你的框架以保持在屏幕的边界内。例如:CGRectMake(40, 50, 320, 480);

相关问题