“<返回”按钮的 Nativescript 行为

Nativescript behavior of the '< Go Back' button

我有以下 ActionBar 定义

<ActionBar class="action-bar" title="Settings"> <NavigationButton text="Go Back" android.systemIcon="ic_menu_back" tap="onBackTap"/> </ActionBar>

确实会调用 Android 版本。

在 iOS 版本中 - 从不调用 onBackTap 方法。

似乎在iOS版本中,即使没有NavigationButton条目,{N}也会自动插入一个。

更新: 事实上,iOS 中的 NavigationButton 似乎只能用于向后导航,不能被 tap 操作覆盖。参考资料来自 the NativeScript documentation

In iOS, the back button is used explicitly for navigation. It navigates to the previous page and you cannot handle the tap event to override this behaviour.

至于 iOS 出现的 NavigationButton - 它是设计使然,就像在本机 iOS 应用程序中一样。如果你不想有后退导航,你可以用

强制它
clearHistory: true

在测试应用程序中取消注释 this line 并从 sub-page 中删除导航按钮,当从 main-page 导航到 sub-page 时,导航按钮将不会出现。

正如@nick 验证的那样,在 {N} 的 iOS 版本上,无法获取导航按钮的点击事件。我理解为什么如果导航按钮不存在,{N} 必须自动添加后退按钮(因为 iPhone 没有物理后退按钮),但不调用现有的点击事件是,恕我直言,在框架中添加不必要的差异.这是 iOS.

的建议逻辑

if NavigationButton present then if tap event handler set by user then use it else auto-gen a tap event handler else auto-gen a back-button and a tap event handler

无论如何,这是我为我的应用解决这个问题的方法。

<NavigationButton visibility="collapse"/> <ActionItem ios.position="left" text="< Back" tap="onBack"/>

这符合我的预期,并且 cross-platform 与 Android 版本兼容。