【问题标题】:Native iOS navigation on React-Native View Component button press按下 React-Native View Component 按钮上的原生 iOS 导航
【发布时间】: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


    【解决方案1】:

    它是黑色的,因为您以编程方式是 initializingviewController 并推送它 UIViewController *detail = [[UIViewController alloc]init];

    试试这个:

    UIViewController *detail = [[UIViewController alloc] init];
    detail.view.backgroundColor = [UIColor whiteColor];
    

    编辑

    除非你需要,否则你不应该真的是 initializing 这样的视图控制器。您应该使用storyboards 创建视图控制器并布置视图,然后将它们呈现到UINavigationViewController 上。这是一个很好的tutorial

    【讨论】:

    • 好久没做iOS开发了,谢谢提醒!我使用了故事板和[rootViewController performSegueWithIdentifier:@"showDetail" sender:nil];,它成功了。
    猜你喜欢
    • 2018-01-26
    • 2018-01-17
    • 2023-02-06
    • 1970-01-01
    • 2019-03-18
    • 1970-01-01
    • 1970-01-01
    • 2022-11-29
    • 2019-08-08
    相关资源
    最近更新 更多