簡體   English   中英

將視圖推送到不在同一視圖層次結構中的UINavigationController

[英]Pushing a view to a UINavigationController that's not in the same view hierarchy

我列出了兩個表格視圖。 一個顯示項目列表,例如配方名稱。 另一個顯示配方名稱以及說明和圖像。 具有更詳細視圖的視圖是導航控制器的一部分,因此輕按這些項目之一可將另一視圖推入堆棧頂部。

問題是我只有配方名稱的列表,點擊該菜單時,我想將該配方詳細信息推入導航控制器堆棧。 這兩個視圖不在同一視圖層次結構中,因此我不能僅以常規方式推送它。

我已經嘗試過將視圖的內容傳遞到主列表中的方法中,以將其推入堆棧,但這沒有任何作用。

因此,有沒有一種方法可以在另一組視圖中訪問導航控制器,以便可以將視圖推入該視圖?

如果有幫助,請使用以下變通辦法來擺脫子視圖中的某些推送問題。 我使用模態segue和推動畫。

您可以像這樣調用它們:[myAnimations modalRight:self destvc:yourDestViewController]。 要回退,請從yourDestViewController:[myAnimations modalLeft:self];

myAnimations.h

#import <Foundation/Foundation.h>

@interface myAnimations : NSObject
@end

myAnimations.m

#import "myAnimations.h"
#import <QuartzCore/QuartzCore.h>

@implementation myAnimations

+(void) modalRight:(UIViewController*)vc destvc:(UIViewController*)viewCtrl{
    CATransition *transition = [CATransition animation];
    transition.duration = 0.3;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;// kCATransitionMoveIn;
    transition.subtype = kCATransitionFromRight;
    [vc.view.window.layer addAnimation:transition forKey:nil];
    [vc presentModalViewController:viewCtrl animated:NO];
}

+(void) modalLeft:(UIViewController*)vc{
    CATransition *transition = [CATransition animation];
    transition.duration = 0.3;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromLeft;
    [vc.view.window.layer addAnimation:transition forKey:nil];
    [vc dismissModalViewControllerAnimated:NO];
}

@end

更新:現在有了IOS 7,它是不錯的推送動畫,上面的方法會使它看起來很奇怪。 如果要模態顯示需要推送內容的viewcotroller(我們稱其為pusherVC),則將pusherVC嵌入導航控制器中,並模態化推送器的導航控制器。 然后,@ pusherVC您可以在當前執行self.nafigationcontroller ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM