UIViewController中!不符合协议" LogicValue"

时间:2014-07-31 11:16:57

标签: ios objective-c uiviewcontroller swift

我正在尝试将以下Objective-c代码转换为swift:

- (UIViewController *)currentViewController
{
    UIViewController *viewController = self.rootViewController;
    while (viewController.presentedViewController) {
        viewController = viewController.presentedViewController;
    }
    return viewController;
}

#ifdef __IPHONE_7_0

- (UIViewController *)viewControllerForStatusBarStyle
{
    UIViewController *currentViewController = [self currentViewController];

    while ([currentViewController childViewControllerForStatusBarStyle]) {
        currentViewController = [currentViewController childViewControllerForStatusBarStyle];
    }
    return currentViewController;
}

- (UIViewController *)viewControllerForStatusBarHidden
{
    UIViewController *currentViewController = [self currentViewController];

    while ([currentViewController childViewControllerForStatusBarHidden]) {
        currentViewController = [currentViewController childViewControllerForStatusBarHidden];
    }
    return currentViewController;
}

#endif   

//SWIFT

func currentViewController() -> UIViewController {

    var viewController = self.rootViewController

    while (viewController.presentedViewController) {
        viewController = viewController.presentedViewController
    }
    return viewController

}

func viewControllerForStatusBarStyle() -> UIViewController {

    var cViewController = currentViewController()

    while (cViewController.childViewControllerForStatusBarStyle) {
        cViewController = cViewController.childViewControllerForStatusBarStyle
    }
    return cViewController


}

func viewControllerForStatusBarHidden() -> UIViewController {

   var cViewController = currentViewController()

        while (cViewController.childViewControllerForStatusBarHidden) {
            cViewController = cVC.childViewControllerForStatusBarHidden
        }

        return cViewController

}

但是我得到一些错误,说UIViewController!在以下行“while(cViewController.childViewControllerForStatusBarStyle)”中不符合协议“LogicValue”

如何解决此问题?

1 个答案:

答案 0 :(得分:2)

childViewControllerForStatusBarStyle()是一种方法而不是属性

   while (cViewController.childViewControllerForStatusBarStyle()) {
        cViewController = cViewController.childViewControllerForStatusBarStyle()
}