0

I have setup a class with the following: MESSidePanelViewControllerSubClass Header file

@property BOOL setLandscapeOK;

Imp file

- (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;
}

I now want to update the value from another file (view controller).
LoginViewController Other view controller imp file

- (NSInteger)supportedInterfaceOrientations {
    // Restriction for the welcome page to only allow potrait orientation
    NSLog(@"Login-supportInterfaceOrientations");
    MESSidePanelViewControllerSubClass* setLandscapeOK = YES;
    return UIInterfaceOrientationMaskAll;
}

I get an error:

Implicit conversion of 'BOOL' (aka 'signed char') to 'MESSidePanelViewControllerSubClass *' is disallowed with ARC

How should I be updated the BOOL value in another file?

iDev
  • 23,310
  • 7
  • 60
  • 85
StuartM
  • 6,743
  • 18
  • 84
  • 160
  • 1
    Perhaps you need to do a little bit more reading on [what properties and instances](http://developer.apple.com/library/ios/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html) are. This is really... weird (assigning a BOOL to an instance of a class named the same as a property of that class) – CodaFi Feb 15 '13 at 21:52
  • instead of `if (setLandscapeOK == YES)`, use `if (self.setLandscapeOK)`. You don't need to compare a `BOOL` to `YES`/`NO`. – nielsbot Feb 17 '13 at 01:17

2 Answers2

0

This line is wrong:

MESSidePanelViewControllerSubClass* setLandscapeOK = YES;

It should be something like this: (Also mESSidePanelViewControllerSubClass is probably an iVar and instantiated somewhere outside your supportedInterfaceOrientations method.)

 MESSidePanelViewControllerSubClass *mESSidePanelViewControllerSubClass = [MESSidePanelViewControllerSubClass alloc] init];

then:

mESSidePanelViewControllerSubClass.setLandscapeOK = YES;

Edited to add link to delegate.

Community
  • 1
  • 1
user523234
  • 14,323
  • 10
  • 62
  • 102
  • Would this not create another instance of the subclass though? These are the steps. Welcome view controller created / Nav controller created / Subclass Reveal side panel created and has nav controller as the presented. Welcome should be portrait only. Login view controller is loaded via a button. The login is pushed to the nav controller, which is still held within the Reveal Side Panel (loaded with sub class). The login should be landscape only. I think the above creates a new instance of the sub class as opposed to updating the one already created? – StuartM Feb 16 '13 at 00:42
  • From what you described, there are several options: A. Use a delegate pattern. B. Passing the reference of the BOOL var. C. Use NSNotification. But using delegate is best choice in my opion for this type acitivies ( see my edited answer with a link to one of my previous answers on this subject.) – user523234 Feb 16 '13 at 04:00
  • set the delegate on the presenting view controller in prepareForSegue (If you're using storyboards, based on the code I see I'm fairly certain you are) and make sure your delegate is a weak property on the presenting view controller, never retain a delegate, well... unless you have an amazingly good reason to anyway... – Holyprin Feb 16 '13 at 04:43
0

Shouldn't -supportedInterfaceOrientations in MESSidePanelViewControllerSubClass always return UIInterfaceOrientationMaskPortrait? If an instance of MESSidePanelViewControllerSubClass is pushed as a child view controller, won't that force your UI orientation to be portrait? Did you try that?

nielsbot
  • 15,922
  • 4
  • 48
  • 73