我们正在向现有应用程序添加本机反应,但无法将本机视图控制器推到另一个包含本机反应视图的本机视图控制器之上。
主视图控制器的 viewDidLoad 如下所示:
-(void)viewDidLoad {
...
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName: @"ListingsView" launchOptions:nil];
self.view = rootView;
}
React 视图是一个 ListView,其中 TouchableHighlight 的 onPress 被导出到同一视图控制器上的此方法:
RCT_EXPORT_METHOD(productClicked:(NSDictionary *)productDict)
{
dispatch_async(dispatch_get_main_queue(),
^{
SNKProduct *product = [[SNKProduct alloc] initWithDictionary:productDict];
SNKProductViewController *vc = [[SNKProductViewController alloc] initWithProduct:product];
[self.navigationController pushViewController:vc animated:YES];
});
}
该方法肯定会被调用,但 SNKProductViewController 永远不会被推送到屏幕上(没有日志消息)。我还尝试以模式方式呈现视图控制器,并收到以下控制台消息:
Warning: Attempt to present <SNKProductViewController: 0x7feadf247d10> on <SNKProductsViewController: 0x7feada5e2a20> whose view is not in the window hierarchy!
任何帮助将不胜感激,非常感谢!
通话后RCT_EXPORT_MODULE
React-Native 的宏创建了该模块的新实例。并在通话后RCT_EXPORT_METHOD
方法 此方法从模块的另一个实例调用。为了解决这个问题,我目前只找到了一个解决方案。在 js 调用的方法中,在层次结构控制器中搜索我的 ViewController:
RCT_EXPORT_MODULE(AuthController);
- (instancetype)init {
self = [super init];
if (self) {
}
return self;
}
- (void)loadView {
self.view = [[RCTRootView alloc] initWithBundleURL:[[BCEConfigs sharedInstance] getBundleOfReactResources]
moduleName:@"AuthorizationView"
launchOptions:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
}
RCT_EXPORT_METHOD(a_registrationButton) {
[self presentRegistrationViewController];
}
- (void)presentRegistrationViewController {
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIViewController *mainViewController = keyWindow.rootViewController.childViewControllers[0];
BCERegistrationViewController *bceRegistrationViewController = [BCERegistrationViewController new];
dispatch_async(dispatch_get_main_queue(), ^{
[mainViewController presentViewController:bceRegistrationViewController animated:YES completion:nil];
});
}
在这个例子中,我需要的控制器有一个地方window>rootViewController>authViewController
UPD
这是我发现的 https://stackoverflow.com/questions/11637709/get-the-current-displaying-uiviewcontroller-on-the-screen-in-appdelegate-m我们如何获取当前 ViewController 的一些解决方案
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)