【发布时间】:2017-07-04 18:23:23
【问题描述】:
我有一个简单的 React-Native 组件ReactNativeMasterView,带有一个我想用于本地导航的按钮。
在ReactNativeMasterView:
var MasterViewController = NativeModules.MasterViewController
然后按钮调用:
MasterViewController.buttonEvent()
我有一个基本的 Obj-C 视图控制器,名为 MasterViewController
在MasterViewController.h:
@interface MasterViewController : UIViewController <RCTBridgeModule>
在MasterViewController.m
我在故事板中引用了 react native 视图:
@property (weak, nonatomic) IBOutlet RNMasterView *reactViewWrapper;
原生模块和方法如下所示:
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(buttonEvent) {
RCTLogInfo(@"Button Pressed");
UIViewController *detail = [[UIViewController alloc]init];
UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
dispatch_async(dispatch_get_main_queue(), ^{
[rootViewController showViewController:detail sender:self];
});
}
它几乎也可以工作......
遗憾的是,转换将我带到黑屏,当我检查视图层次结构时,UITransitionView 似乎只是呈现一个空的View,我实际上也可以从这个状态导航回来。
有人知道如何完成这项工作吗?
更新:
我可以让它与 UIAlertController 一起工作:
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:name
message:param
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
NSLog(@"Cancel");
}];
[alert addAction:cancelAction];
UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
dispatch_async(dispatch_get_main_queue(), ^{
[rootViewController presentViewController:alert animated: YES completion: nil];
});
这似乎按预期工作。
【问题讨论】:
标签: ios objective-c react-native uinavigationcontroller navigation