0

I'm trying to use the project SideMenu (https://github.com/jonkykong/SideMenu) inside my Objective-C code (I saw the @objc/@objcMembers syntax so I'm guessing it should be possible) and I'm not using storyboards. Can the controller be used in this scenario? If so, how? It seems I correctly imported the module as I'm able to see the classes with autocompletion, but if I try to instantiate a SideMenuNavigationController, I cannot access the initWithRootViewController method. Is there anybody who could point me in the right direction? Thanks

zionun
  • 51
  • 4
  • In swift it will be: `SideMenuNavigationController(rootViewController: YourViewController)` or `SideMenuNavigationController.init(rootViewController: YourViewController)` – Cy-4AH Sep 29 '20 at 15:36
  • Yes, that's what I found on the documentation. In Obj-C I would do `[[SideMenuNavigationController alloc] initWithRootViewController:YourViewController]`, but it doesn't recognize the method, even if there's the @objcMembers declaration in the Swift code. Any idea? – zionun Sep 30 '20 at 10:36

2 Answers2

0

Not sure if you already figured this out, but in Objective-C, the class is exposed as UISideMenuNavigationController instead. So, you end up with:

UISideMenuNavigationController *menu = [[UISideMenuNavigationController alloc] initWithRootViewController:controller];
Jeremy Hicks
  • 3,690
  • 5
  • 40
  • 52
  • Hi Jeremy, thank you for your suggestion. Unfortunately, I get an error when trying your solution: `'initWithRootViewController:' is unavailable Unknown receiver 'UISideMenuNavigationController'; did you mean 'SideMenuNavigationController'? Replace 'UISideMenuNavigationController' with 'SideMenuNavigationController'` Replacing UISideMenuNavigationController with SideMenuNavigationController leads to the error: `'initWithRootViewController:' is unavailable` – zionun Nov 05 '20 at 15:29
  • @zionun : have you find the solution.i am facing same issue. – Daxesh Nagar May 25 '21 at 15:49
  • @DaxeshNagar Yes, I used a fork of the project. You can put it in your Podfile like this: `pod 'SideMenu', :git => 'https://github.com/DanielFontes/SideMenu.git', :commit => '52361cfee8cd89698cc131729d9f337d8fafcffe';` Then, you can instantiate it as you normally would with an Objective-C class. – zionun May 27 '21 at 07:22
  • @DaxeshNagar Here is an example of how I used it in my project: `SideMenuSettings *_settings = [[SideMenuSettings alloc] init]; [_settings setPresentationStyle:SideMenuPresentationStyle.menuSlideIn]; SideMenuPresentationStyle *_style = _settings.presentationStyle; _style.presentingScaleFactor = 0.9; SideMenuNavigationController *_sideMenu = [[SideMenuNavigationController alloc] initWithRootViewController:sectionsView settings:_settings]; [_sideMenu setLeftSide:YES]; [[SideMenuManager defaultManager] setLeftMenuNavigationController:_sideMenu];` – zionun May 27 '21 at 07:29
0

Here is the solution I adopted, in case someone was running into the same problem. In your pod file, use this fork of the SideMenu project:

pod 'SideMenu', :git => 'https://github.com/DanielFontes/SideMenu.git', :commit => '52361cfee8cd89698cc131729d9f337d8fafcffe';

Then, you can instantiate SideMenu as you normally would with an Objective-C class; here is how I configured it in my project:

YourViewController *_view = [[YourViewController alloc] initWithNibName:@"NibName" bundle:nil];

SideMenuSettings *_settings = [[SideMenuSettings alloc] init];
[_settings setPresentationStyle:SideMenuPresentationStyle.menuSlideIn];
SideMenuPresentationStyle *_selectedPresentationStyle = _settings.presentationStyle;
_selectedPresentationStyle.presentingScaleFactor = 0.9;

float width = (self.isiPad)?570:300;
[_settings setMenuWidth:width];
            
SideMenuNavigationController *_sideMenu = [[SideMenuNavigationController alloc] initWithRootViewController:_view settings:_settings];
[_sideMenu setSideMenuDelegate:self];
[_sideMenu setNavigationBarHidden:YES];
[_sideMenu setLeftSide:YES];
[_sideMenu setStatusBarEndAlpha:0];
            
[[SideMenuManager defaultManager] setLeftMenuNavigationController:_sideMenu];
[[SideMenuManager defaultManager] addPanGestureToPresentToView:_firstViewController.navigationController.navigationBar];
[[SideMenuManager defaultManager] addScreenEdgePanGesturesToPresentToView:_firstViewController.view];

zionun
  • 51
  • 4