我正在尝试从快捷类中加载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
我的InitialViewController
是一个objective-c
类,可以通过编程方式加载UI。
我的意图是从swift类的方法中加载Initialviewcontroller
,我将通过NativeModules从本机反应中调用该特定方法。
@objc func startChat ()
{
self.navigationController!.pushViewController(self.storyboard!.instantiateViewControllerWithIdentifier("initialViewController") as UIViewController, animated: true)
}
}
上面的函数将错误显示为
“ ChatManager没有成员NavigationController”。
请让我知道如何从该swift类中调用此viewcontroller。
答案 0 :(得分:0)
@objc func startChat (){
let initialVC = initialViewController()
self.navigationController?.pushViewController(initialVC, animated: true)
}