1
如何在RN中調用本機iOS viewController的代碼?React本機調用iOS ViewController
就像使用RN推送到本地iOS viewController然後讓本地代碼執行這項工作。
如何在RN中調用本機iOS viewController的代碼?React本機調用iOS ViewController
就像使用RN推送到本地iOS viewController然後讓本地代碼執行這項工作。
您需要使用導出方法。
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];
}
pushVC方法需要一個PARAM以指示哪些的viewController被推。 –
@RainerLiao回答更新 – Rahul
感謝您的留言。但是如何在React Native中調用這個方法? – rocLv