iOS Question Subclass Page (UIViewController)

Semen Matusovskiy

Well-Known Member
Licensed User
Hi, guys --

To subclass UIViewController in XCode is enough simple due to wizards. For example,

B4X:
#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController
@end
@implementation FirstViewController
- (BOOL) prefersStatusBarHidden { NSLog(@"prefersStatusBarHidden"); return YES; }
@end
But how to do the same in B4I ?
I tried to use Erel's shouldAutorotate as layout. shouldAutorotate works, but methods, which I try to add, are not called.

Any ideas ?
 

Semen Matusovskiy

Well-Known Member
Licensed User
In B4I I created a new project and added
B4X:
#if OBJC
@end
@interface UIViewController (Test)
@end
@implementation UIViewController (Test)
- (BOOL) shouldAutorotate { NSLog (@"shouldAutorotate"); return true; }
- (BOOL) prefersStatusBarHidden { NSLog(@"StatusBar"); return YES; }
- (UIStatusBarStyle) preferredStatusBarStyle { NSLog(@"StatusBarStyle"); return UIStatusBarStyleLightContent; }
#End If
shouldAutorotate is called, other methods - not.

In Catalyna, XCode 11.1 I created a new project using "Tabbed App". In FirstViewController.m inside @implementation FirstViewController I added
B4X:
- (UIStatusBarStyle) preferredStatusBarStyle { NSLog(@"FirstView: preferredStatusBarStyle"); return UIStatusBarStyleLightContent; }
- (BOOL) prefersStatusBarHidden { NSLog(@"FirstView: prefersStatusBarHidden"); return YES; }
Then an analog code for SecondViewController.
B4X:
- (BOOL) prefersStatusBarHidden { NSLog(@"SecondView: prefersStatusBarHidden"); return NO; }
- (UIStatusBarStyle) preferredStatusBarStyle { NSLog(@"SecondView: preferredStatusBarStyle"); return UIStatusBarStyleDarkContent; }
Works fine.

After this I added to main.m the same code as in B4I. IOS works as expected (methods are called inside main.m and First/SecondViewController).
 
Last edited:
Top