問題描述
我有一個 Ext.navigation.View,我在其中推送了一些視圖.某些用戶交互要求我直接返回導航視圖的頂層——相當于 iOS 中 UINavigationController 上的 popToRootViewControllerAnimated:.
I have an Ext.navigation.View in which I have pushed a few views. Certain user interactions require that I go directly back to the top level of the navigation view -- the equivalent of popToRootViewControllerAnimated: on a UINavigationController in iOS.
我嘗試過各種方法,例如:
I have tried various things like:
while(navigationView.getItems().getCount() > 1)
navigationView.pop();
和
while(navigationView.canPop())
navigationView.pop();
都不行.第一個例子似乎讓我陷入了無限循環,這并不奇怪.第二個例子似乎只彈出一個視圖.
Neither work. The first example seems to put me into an infinite loop which isn't too surprising. The second example only seems to pop one view off.
所以問題是:在 Sencha Touch(版本 2 開發者預覽版)中的 Ext.navigation.View 中彈出到根視圖的正確方法是什么?
So the question: What is the proper way to pop to the root view in an Ext.navigation.View in Sencha Touch (version 2 developer preview)?
推薦答案
有許多臨時方法可以實現這一目標.
There has been a number of interim methods for achieving this.
我使用的是彈出一個比你曾經擁有的級別數更高的數字,例如
The one I was using was to pop a number higher than the number of levels you would ever have e.g.
navigationView.pop(10);
效果很好,但我對此并不滿意,但我看到他們現在引入了一種重置方法.你可以這樣稱呼它......
and that worked fine, but I was never happy with that, but I see they have now introduced a reset method. Which you can call thus...
navigationView.reset();
在 Sencha 源代碼內部(見下文),您可以看到它與 @Mithralas 所說的工作類似,但更容易編寫.
Internally within the Sencha source code (see below) you can see that it does a similar job to what @Mithralas said, but just easier to write.
// From the Sencha source code
this.pop(this.getInnerItems().length);
這篇關于Sencha Touch Ext.navigation.View pop to root的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!