Xcode 4 UIButton segue推送到Table View Controller [英] Xcode 4 UIButton segue push to Table View Controller

查看:56
本文介绍了Xcode 4 UIButton segue推送到Table View Controller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我的故事板中有一个 UIButton 设置,可以推送到Table View Controller。这是按预期工作的。我想要做的是让 UIButton 在按下时加载一个xml文件并仍然移动到表视图控制器上。

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.

我该怎么做?我已经有了XML代码的代码,这是代码将去哪里以及如何为新的ViewController子类 UIViewController 添加.h和.m文件的问题。如何将这些文件链接到我在故事板中创建的 UIButton

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?

推荐答案

将按钮连接拖到新视图并选择自定义Segue而不是Push或Modal。

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

将新的自定义Segue的类更改为mySegueClass1或者您想要的任何内容叫它。

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

创建一个新的Objective-C类,其名称与刚刚分配给自定义segue的名称相同。

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


然后在mySegueClass1.m文件中添加以下代码,并添加其他操作你想要 - (无效)执行

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

这篇关于Xcode 4 UIButton segue推送到Table View Controller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆