Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

ios - Pushing a view to a UINavigationController that's not in the same view hierarchy

I have two table views set out. One shows a list of items, say recipe names. The other shows recipe names with descriptions and images. The one with the more detailed view is part of a navigation controller so tapping one of those items pushes another view on top of the stack.

The problem is I have the list of just the recipe names that when tapped I want to push that recipe detail on to the navigation controller stack. These two views are not in the same view hierarchy so I can't just push it in the normal manner.

I've tried passing the content for the view to be pushed onto the stack into a method on the main list, but that didn't do anything.

So, is there a way to get to a navigation controller in another set of views so I can push a view onto it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If it helps you, here is a workaround I used to get rid of some push issues from subviews. I use a modal segue, with push animation.

You can call them like: [myAnimations modalRight:self destvc:yourDestViewController]. To segue back, from 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

UPDATE: now with IOS 7 and it's nice push animation, the method above will make it look strange. If you want to present modally a viewcotroller that needs to push something (let's call it pusherVC), embed pusherVC in a navigation controller, and present modal the pusher's navigation controller. Then, @ pusherVC you can do self.nafigationcontroller present...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...