在 RN 中如何调用 native iOS viewController 的代码?
就像使用 RN 推送到 native iOS viewController 然后让 native 代码完成这项工作一样。
最佳答案
您需要使用导出方法。
AppDelegate.h
#import <UIKit/UIKit.h>
#import "RCTBridgeModule.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate,RCTBridgeModule>
@property (nonatomic, strong) UIWindow *window;
@end
AppDelegate.m
@implementation AppDelegate
RCT_EXPORT_MODULE()
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//NO Change Here
}
RCT_EXPORT_METHOD(pushVC:(NSString *)vcName){
Class ctrlClass = NSClassFromString(vcName);
UIViewController *newVc = [[ctrlClass alloc] initWithNibName: vcName bundle: nil];
[[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:newVc animated:YES completion:nil];
}
关于ios - React Native 调用 iOS ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35906967/