Xcode 4 UIButton segue push to Table View Controller

Now I have a UIButton setting in my storyboard that pushes the Table View Controller. This works as expected. What I'm trying to do is load the UIButton xml file when I click it and still navigate to the table view controller.

How can i do this? I already have the XML snippets code, this is a question about where the code will go, and how I will add the .h and .m files for the new subclass of ViewController UIViewController . How do I link these files to the UIButton that I created in the storyboard?

+2
source share
2 answers

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

enter image description here

Change the new custom Segue class to "mySegueClass1" or whatever you want to name.

enter image description here

Create a new Objective-C class with the same name as the custom segment.

enter image description here Then in the mySegueClass1.m file add the following code and add what additional actions you want to do -(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]; } 
+5
source

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. } 

This is called before executing segue. Here you can perform all the necessary settings. You should put this method inside the controller that executes the segue, and not the one that receives it. (Actually, probably xcode already placed this piece of code for you).

+3
source

Source: https://habr.com/ru/post/911490/


All Articles