Search code examples
objective-ciosxcodeios5storyboard

Xcode 4 UIButton segue push to Table View Controller


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 UIButton load an xml file when it is pressed and still move onto the Table View Controller.

How can I do this? I already have the code the XML pieces, it's a question of where the code would go and how I would add the .h and .m files for a new ViewController subclass UIViewController. How do I link those files to the UIButton I've created in storyboard?


Solution

  • 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];
    }