Moving back from a Controller to a previous one

后端 未结 2 1288
温柔的废话
温柔的废话 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 
    
    @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}];
        }
    }
    

提交回复
热议问题