如何弹出viewController,然后通过委托推送viewController [英] How to pop a viewController and then Push a viewController through delegation

查看:127
本文介绍了如何弹出viewController,然后通过委托推送viewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableViewController,当按下一个单元格时,我希望控制器自行弹出,然后将控制器弹出,将另一个视图控制器推入堆栈。

I have a UITableViewController that when a cell is pressed, I want the controller to pop itself, and then have the controller it pop's to, push another view controller onto the stack.

我正在调用此方法,因为popped-to viewController是tableViewController的委托

I am invoking this method because the popped-to viewController is the delegate of the tableViewController

我正在调用此方法并延迟它,否则一切都搞砸了,等待动画结束。这样做似乎有点hacky,在我看来,如果有人的设备没有在我给出的分配的等待时间内弹出视图,它会失败。

I am currently invoking this method with a delay on it, because otherwise, everything gets screwed up waiting for the animation to end. Doing it this way seems a bit hacky and seems to me like it would fail if someone's device didn't pop the view in the allotted wait time I have given it.

以下是一些代码:

//**** code in my tableViewController ***//

[self.navigationController popViewControllerAnimated:YES];
[self.delegate cellPressedInTableViewControllerWithCalculationsModel:(id)anArgmentMyDelegateMethodTakes];



// **** Code in the viewController being popped to ****//
//CalculationsViewController is a subclass of UIViewController
CalculationsViewController *calcViewController = [[CalculationsViewController alloc] init];

//some customization code would go her

[self.navigationController performSelector:@selector(pushViewController:animated:) withObject:calcViewController afterDelay:0.75];
//this seems like the arbitrary part, the 0.75 second delay.

[calcViewController release];

似乎应该有更好的方法来弹出/推送将在动画后执行的委托饰面。等待时间在我看来可能会导致意外问题。

There seems like there should be a better way to pop/push through delegation that will execute after the animation finishes. The wait time seems to me like it could cause unexpected problems.

我也尝试过使用:

 performSelectorOnMainThread:withObject:waitUntilDone

但是代码只是立即执行而且视图层次结构搞砸了。

But the code just executes immediately and the view hierarchy screwed up.

我也看过这个问题:
委托问题
它让我走到这一步,但我很想知道是否有更好的方法来执行这样的任务,
谢谢。

I have also looked at this question: Delegation question and it has gotten me this far, but I am curious to see if there is a better way to perform such a task, Thanks.

编辑:我也尝试在NSInvocation的实例中包装该方法,我无法让它协调方法调用,直到动画完成后没有任意设置延迟

edit: I have also tried wrapping the method in an instance of NSInvocation, and I couldn't get it to coordinate the method call until after the animation finished without arbitrarily setting the delay

推荐答案

你应该使用一个标志来克服这种情况。您在视图控制器的viewWillDisappear方法中设置此标志。设置此标志然后您可以在堆栈上推送另一个视图控制器。希望很清楚。

You should use a flag to overcome this situation. You set this flag in viewWillDisappear method of view controller being popped. When this flag is set then and then you can push another view controller on stack. Hope it's clear.

这篇关于如何弹出viewController,然后通过委托推送viewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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