2012-03-07 39 views
2

现在我有一个UIButton安装在我的故事板中,推到一个表视图控制器。这是按预期工作的。我正在尝试做的事情是,UIButton按下时加载一个xml文件,并仍然移动到Table View Controller上。Xcode 4 UIButton继续推送到桌面视图控制器

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

回答

5

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

enter image description here

更改新的自定义Segue公司的类“mySegueClass1”或什么都你想调用它。

enter image description here

具有相同的名称创建一个新的Objective-C类,你刚刚分配到自定义SEGUE。

enter image description here 然后你mySegueClass1.m文件中添加以下代码,并添加你什么都想要更多的行动,以-(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

我刚刚有机会实现此代码今天(妻子有一个孩子),它的作品完美。花时间做出如此彻底的回应,我感激不尽。 – cmutchler 2012-03-09 22:28:39

+0

什么都没问题,恭喜! – 2012-03-09 22:32:05

3

有一种方法:

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

这就是所谓的在进行阶段之前。在这里你可以做所有你需要的设置。您应该将此方法放置在执行segue的控制器中,而不是接收它的控制器。 (事实上​​,xcode可能已经为你提供了这段代码)。

相关问题