2012-12-27 4 views
2

내 응용 프로그램 중 하나에서 TDD을 모두 시도 중이므로 ViewController가 모달 방식으로 팝업되는지 확인할 수있는 방법이 있습니까? 마찬가지로어떤 viewcontroller가 모달로 표시되었는지 확인하는 방법

는 논리 지점에서 나는 호출하는 경우 : 제시 년대의 ViewController에이를 테스트 할 수있는 방법이

[self presentModalViewController:myModalControl]; 

가?

[mainVC_SUT presentedViewController] 

[mainVcSUT modalViewController] 

을하지만 모두가 전무로 돌아 오면 :

나는 시도했다. mainVC_SUT은 프리젠 테이션을 수행하는 뷰 컨트롤러입니다. 추천하기 추천

답변

0

확인 :

if ([self.parentViewController.modalViewController isEqual:self]) 
    NSLog(@"I'm modal view controller!"); 
else 
    NSLog(@"I'm a push view controller!"); 
0
-(BOOL)isModal { 

    BOOL isModal = ((self.parentViewController && self.parentViewController.modalViewController == self) || 
        //or if I have a navigation controller, check if its parent modal view controller is self navigation controller 
        (self.navigationController && self.navigationController.parentViewController && self.navigationController.parentViewController.modalViewController == self.navigationController) || 
        //or if the parent of my UITabBarController is also a UITabBarController class, then there is no way to do that, except by using a modal presentation 
        [[[self tabBarController] parentViewController] isKindOfClass:[UITabBarController class]]); 

    //iOS 5+ 
    if (!isModal && [self respondsToSelector:@selector(presentingViewController)]) { 

     isModal = ((self.presentingViewController && self.presentingViewController.modalViewController == self) || 
        //or if I have a navigation controller, check if its parent modal view controller is self navigation controller 
        (self.navigationController && self.navigationController.presentingViewController && self.navigationController.presentingViewController.modalViewController == self.navigationController) || 
        //or if the parent of my UITabBarController is also a UITabBarController class, then there is no way to do that, except by using a modal presentation 
        [[[self tabBarController] presentingViewController] isKindOfClass:[UITabBarController class]]); 

    } 

    return isModal;   

} 

제공 :http://www.allenwei.cn/ios-determine-current-view-is-a-modal/

관련 문제