我正在尝试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 类中调用这个视图控制器。