2014-06-24 31 views
1

我有一個應用程序,我有3 UINavigation可以通過自定義菜單相互切換的堆棧。當從堆棧A切換到堆棧B或C時,它看起來像新的部分被推送到當前的導航堆棧上,因爲堆棧B/C的RootViewController都有後退按鈕,可以彈回到先前的堆棧。用戶可以使用自定義菜單導航回到堆棧A,或者點擊堆棧B/C RootViewController上的後退按鈕,這會將它們帶回堆棧A所在的位置。管理多個UINavigationController堆棧的最佳實踐

我遇到的問題是計算找出跟蹤用戶是否在堆棧A中的最好方法。如果他們在堆棧A中第四次鑽取,切換到堆棧B,然後切換回堆棧A,我需要準確顯示他們以前的位置在堆棧A的流程中。

我是否應該使用多個UINavigationController s,或者有沒有一種方法可以實現這一點而沒有太多的麻煩(即可能使用UIViewController遏制)?

+0

您目前使用什麼代碼在三個導航控制器之間切換?這聽起來像你需要使用類似標籤欄控制器(隱藏導航欄),所以你有一個容器控制器來容納你的3堆棧。 – rdelmar

回答

1

您可以使用遏制以某種方式更改導航控制器,是的,但您當然不需要那樣做。在替換它之前,您可以在UINavigationController中抓取整個堆棧,並跟蹤您的3個堆棧,像數組或字典這樣的結構。

typedef { 
    Section1, 
    Section2, 
    Section3 
} Section; 

.. 

@property (nonatomic, assign) Section currentSection; 
@property (nonatomic, strong) NSMutableArray currentStacks; //Initialize this was the base stacks for each section (i.e an NSArray with just 1 controller for each slot) 
@property (nonatomic, strong) UINavigationController *navigationController; 

.. 

- (void)setSection:(Section)section 
{ 
    self.stacks[self.currentSection] = [self.navigationController.controllers copy];//Save stack for the current section 
    [self.navigationController setViewController:self.stacks[section] animated:YES]; 
    self.currentSection = section; 
} 
0

只要你沒有與任何性能問題,我的建議是保持內部獨立UINavigationControl -s所有需要的視圖控制器堆棧。因此,您將擁有與菜單中的項目一樣多的導航控制器對象。在這種情況下,你將會遇到更少的問題,並且你的邏輯將更加清晰。

這種方法並不需要太多的內存,因爲用量最大的是的UIView層次,而不是的UIViewController -s或的UINavigationController -s。