Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从另一个类更新布尔值_Ios_Ios5_Uiviewcontroller_Boolean_Implicit Conversion - Fatal编程技术网

Ios 从另一个类更新布尔值

Ios 从另一个类更新布尔值,ios,ios5,uiviewcontroller,boolean,implicit-conversion,Ios,Ios5,Uiviewcontroller,Boolean,Implicit Conversion,我已使用以下内容设置了一个类: MessidePanelViewController子类 头文件 @property BOOL setLandscapeOK; Imp文件 - (NSInteger)supportedInterfaceOrientations { // Restriction for the welcome page to only allow potrait orientation if (setLandscapeOK == YES) { N

我已使用以下内容设置了一个类: MessidePanelViewController子类 头文件

@property BOOL setLandscapeOK;
Imp文件

- (NSInteger)supportedInterfaceOrientations {
    // Restriction for the welcome page to only allow potrait orientation

    if (setLandscapeOK == YES) {
        NSLog(@"Reveal-setting all");
        return UIInterfaceOrientationMaskAll;
    }
    NSLog(@"Reveal-setting portrait");
    return UIInterfaceOrientationMaskPortrait;
}
现在我想从另一个文件(视图控制器)更新该值。
逻辑视图控制器 其他视图控制器imp文件

- (NSInteger)supportedInterfaceOrientations {
    // Restriction for the welcome page to only allow potrait orientation
    NSLog(@"Login-supportInterfaceOrientations");
    MESSidePanelViewControllerSubClass* setLandscapeOK = YES;
    return UIInterfaceOrientationMaskAll;
}
我得到一个错误:

Implicit conversion of 'BOOL' (aka 'signed char') to 'MESSidePanelViewControllerSubClass *' is disallowed with ARC
如何更新另一个文件中的布尔值?

此行错误:

MESSidePanelViewControllerSubClass* setLandscapeOK = YES;
它应该是这样的:(另外,MessidePanelViewController子类可能是一个iVar,并在supportedInterfaceOrientations方法之外的某个地方实例化。)

然后:


编辑以添加链接。

不应
-在
MessidePanelViewController子类中支持的接口方向
始终返回
UIInterfaceOrientationMaskPortrait
?如果将
MESSidePanelViewControllerSubClass
的实例作为子视图控制器推送,这是否会强制用户界面方向为纵向?你试过了吗?

也许你需要多读一点are。这真的是。。。怪异(将布尔赋值给与该类的属性名相同的类的实例)而不是
if(setLandscapeOK==YES)
,使用
if(self.setLandscapeOK)
。您不需要将
BOOL
YES
/
NO
进行比较。但这不会创建子类的另一个实例吗?这些是步骤。创建了欢迎视图控制器/创建了导航控制器/创建了子类显示侧面板,并显示了导航控制器。欢迎只应该是肖像。登录视图控制器通过按钮加载。登录被推送到导航控制器,导航控制器仍然保持在侧面板内(加载了子类)。登录名应仅为横向。我认为上面创建了子类的新实例,而不是更新已经创建的实例?根据您所描述的,有几个选项:a.使用委托模式。B.传递布尔变量C的引用。使用NSNOTIONG。但在我看来,使用委托是这类活动的最佳选择(请参阅我编辑的答案,其中有一个链接指向我以前关于这一主题的答案之一)。在prepareForSegue中的presenting view controller上设置委托(如果您使用的是故事板,根据我看到的代码,我很确定您是这样的)并确保您的委托是演示视图控制器上的弱属性,永远不要保留委托,好吧。。。除非你有一个非常好的理由。。。
 MESSidePanelViewControllerSubClass *mESSidePanelViewControllerSubClass = [MESSidePanelViewControllerSubClass alloc] init];
mESSidePanelViewControllerSubClass.setLandscapeOK = YES;