Moving back from a Controller to a previous one

后端 未结 2 1285
温柔的废话
温柔的废话 2020-12-16 22:08

I\'m trying to switch back from my UIViewController to my UITableViewController but apperendly it\'s not working the way I want it to. I did create my Interface with storybo

相关标签:
2条回答
  • 2020-12-16 22:27

    You don't push back. That creates a new instance of the previous controller class. You pop back. You can accomplish that 2 ways.

    1: In code put in the following statement when you want to return (pop) to you tablet view controller.

    [self.navigationController popViewControllerAnimated:YES];

    2: If you want to do it in storyboard you need to implement the following custom segue class:

    implementation

    //  PopSegue.m
    
    #import "PopSegue.h"
    
    @implementation PopSegue
    
    - (void) perform {
    
        UIViewController *src = (UIViewController *) self.sourceViewController;
    [src.navigationController popViewControllerAnimated:YES];
    }
    

    and header

    //  PopSegue.h
    
    #import <UIKit/UIKit.h>
    
    @interface PopSegue : UIStoryboardSegue
    
    @end
    

    Place this method in your UIViewController to set a property back to your UITableViewController:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if ([[segue identifier] isEqualToString:@"goBackToTableView"])  {
        [[segue destinationViewController] set{whatEverProperyYouWantTo}: {valueOfPropertyToSet}];
        }
    }
    
    0 讨论(0)
  • 2020-12-16 22:37

    @T.J When adopt this method "2: If you want to do it in storyboard you need to implement the following custom segue class:

    implementation"

    and according to the document of the following, "Configuring the Destination Controller When a Segue is Triggered iOS performs the following tasks when a segue is triggered:

    It instantiates the destination view controller. It instantiates a new segue object that holds all the information for the segue being triggered. Note: A popover segue also provides a property that identifies the popover controller used to control the destination view controller. It calls the source view controller’s prepareForSegue:sender: method, passing in the new segue object and the object that triggered the segue. It calls the segue’s perform method to bring the destination controller onto the screen. The actual behavior depends on the kind of segue being performed. For example, a modal segue tells the source view controller to present the destination view controller. It releases the segue object and the segue is complete."

    It instantiates the presenting viewController once more, then dealloc after the overrid method of "perform" called. So It is better to choose the first method you submited or the methodof the delegate according the document.

    Thanks

    0 讨论(0)
提交回复
热议问题