Xcode 4 UIButton segue push to Table View Controller

后端 未结 2 740
执念已碎
执念已碎 2021-01-07 03:54

Right now I have a UIButton setup in my storyboard that pushes to a Table View Controller. This is working as expected. What I am trying to do is have the

相关标签:
2条回答
  • 2021-01-07 04:38

    Drag your button connection to the new view and select custom Segue instead of Push or Modal.

    enter image description here

    Change the new custom Segue's class to "mySegueClass1" or what ever you'd like to call it.

    enter image description here

    Create a new Objective-C class with the same name as you just assigned to the custom segue.

    enter image description here Then inside your mySegueClass1.m file add the following code, and add what ever additional actions you want to -(void)perform

    -(void)perform{
        UIViewController *dst = [self destinationViewController];
        UIViewController *src = [self sourceViewController];
        [dst viewWillAppear:NO];
        [dst viewDidAppear:NO];
    
    
        [src.view addSubview:dst.view];
    
        CGRect original = dst.view.frame;
    
        dst.view.frame = CGRectMake(dst.view.frame.origin.x, 0-dst.view.frame.size.height, dst.view.frame.size.width, dst.view.frame.size.height);
    
        [UIView beginAnimations:nil context:nil];
        dst.view.frame = CGRectMake(original.origin.x, original.origin.y, original.size.height, original.size.width);
        [UIView commitAnimations];
    
        [self performSelector:@selector(animationDone:) withObject:dst afterDelay:0.2f];
    }
    - (void)animationDone:(id)vc{
        UIViewController *dst = (UIViewController*)vc;
        UINavigationController *nav = [[self sourceViewController] navigationController];
        [nav popViewControllerAnimated:NO];
        [nav pushViewController:dst animated:NO];
    }
    
    0 讨论(0)
  • 2021-01-07 04:38

    There is a method:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        //You can access the tableviewcontroller using segue.destinationViewController
        //Maybe you want to set your model here.
    }
    

    That is called before a segue is made. Here you can do all the setup you need. You should place this method inside the controller that performs the segue, not the one receiving it. (In fact, probably xcode already put that piece of code for you).

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