0

我正在尝试Initialviewcontroller从 swift 类加载

我的快速课程(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)
  }
}

我的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

MyInitialViewController是一个objective-c以编程方式加载 UI 的类。

我的意图是Initialviewcontroller从 swift 类中的方法加载,我将通过 NativeModules 从 react native 调用该特定方法。

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

上面的函数显示错误为

“ChatManager 没有成员 NavigationController”。

请让我知道如何从那个 swift 类中调用这个视图控制器。

4

1 回答 1

0
@objc func startChat (){
    let initialVC = initialViewController()
    self.navigationController?.pushViewController(initialVC, animated: true)
}
于 2019-04-09T11:44:48.390 回答