0

I'm trying to load Initialviewcontroller, from swift class

My swift class (ChatManager.swift)

 import Foundation;

import UIKit;


@objc(ChatManager)
class ChatManager: NSObject {

  @objc func addEvent(name: String, location: String, date: NSNumber) -> Void {
    // Date is ready to use!

  }

  @objc func startChat ()
  {
    self.navigationController!.pushViewController(self.storyboard!.instantiateViewControllerWithIdentifier("initialViewController") as UIViewController, animated: true)
  }
}

My Appdelegate.m

    #import "AppDelegate.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>


@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"RnBridgeBoldChat"
                                            initialProperties:nil];

  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end

My InitialViewController is an objective-c class which loads UI programmatically.

My intention is to load Initialviewcontroller from a method in swift class, I will call that particular method from react native via NativeModules.

  @objc func startChat ()
  {
    self.navigationController!.pushViewController(self.storyboard!.instantiateViewControllerWithIdentifier("initialViewController") as UIViewController, animated: true)
  }
}

Above function showing error as

"ChatManager has no member NavigationController".

Please let me know how to call this viewcontroller from that swift class.

Bhavesh Nayi
  • 705
  • 4
  • 15
Kartiikeya
  • 2,358
  • 7
  • 33
  • 68

1 Answers1

0
@objc func startChat (){
    let initialVC = initialViewController()
    self.navigationController?.pushViewController(initialVC, animated: true)
}
Braham Youssef
  • 479
  • 6
  • 6