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
744 views
in Technique[技术] by (71.8m points)

ios - How to create a back button in a view controller to go to parent view controller

hi I have a view controller with a container and in the container a child view with a collection view when the user taps the collection view cell it sends me to detail view controller but now what i want to do is to add a back button in my detail view controller which sends me to the parentViewController

enter image description here

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Case 1 : Unwind Segue

This will work perfect according to your situation:

iOS Unwind Segue

Unwind Segues give you a way to “unwind” the navigation stack and specify a destination to go back to.

Case 2 : PopToRootViewController

If you Parent view is also your Root view controller, then you can easily get back using popToRootViewControllerAnimated:YES.

Create own back button add it to navigation bar with method backButtonTouch.

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Back", nil) style:UIBarButtonItemStyleDone target:self action:@selector(backButtonTouch:)]; 

Add above code into viewDidLoad.

-(void)backButtonTouch:(id)sender{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

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

...