Xcode 4 UIButton继续推送到表视图控制器
现在我的故事板中有一个UIButton
安装程序,它推送到一个表视图控制器。 这是按预期工作。 我想要做的是有UIButton
按下时,加载一个XML文件,仍然移动到表视图控制器。
我怎样才能做到这一点? 我已经有了代码的XML片断,这是一个问题的代码将去,以及如何添加一个新的ViewController子类UIViewController
的.h和.m文件。 如何将这些文件链接到我在故事板中创build的UIButton
?
拖动你的button连接到新的视图,并select自定义Segue而不是Push或者Modal。
将新的自定义Segue的类更改为“mySegueClass1”,或者你想称之为什么。
创build一个新的Objective-C类,其名称与您刚分配给自定义的segue的名称相同。
然后在你的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]; }
有一种方法:
- (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已经把这段代码给你了)。