【问题标题】:Custom UIViewController IOS4.3自定义UIViewController IOS4.3
【发布时间】:2012-08-20 11:01:26
【问题描述】:

我有静态库和我的自定义视图控制器(f.e mainVC)。 我的静态库将在一些第三方应用程序中构建。

我必须在第三个应用启动后立即显示 mainVC.view。 我愿意:

[window addSubView:mainVC.view];

但是我怎样才能使我的 mainVC 处于活动状态?这意味着我必须在

中否认横向
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

在这种情况下,这个方法永远不会调用。

我也试过手动调用

[self.mainVC viewWillAppear:NO];

但还是失败了。

也许我应该使用

-(void)presentModalViewController:animated

但它已被弃用。而且我必须支持IOS 4.3

【问题讨论】:

    标签: ios uiviewcontroller modalviewcontroller ios4 presentmodalviewcontroller


    【解决方案1】:

    您可能希望在调用该方法之前检查该类是否允许响应该方法。

    if([self respondsToSelector:@selector(presentViewController:animated:completion:)]) 
    {
        [self presentViewController:viewController animated:YES];
    }
    else
    {
        //some other methods
    }
    

    这样您可以使用已弃用的方法来支持 IOS 4.3,并为更高的 IOS 版本使用另一种解决方案

    【讨论】:

    • 正确的方法是使用if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) [self presentViewController:viewController animated:animated completion:completionBlock]; else { ... }
    • 注:对4.3的方法不太了解,所以抄自他自己的问题方法。如果您想要向后兼容,这个想法保持不变
    • 其实这不是我所需要的。我必须像弹出窗口一样显示 mainVC.view(与 FBDialog 一样),如果我以模态方式呈现 mainVC 并设置 mainVC.view 边距......它在我的 mainVC.view 周围有黑色区域
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-18
    • 2019-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多