关闭模式视图控制器 [英] Dismissing Modal View Controllers

查看:83
本文介绍了关闭模式视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的流程:

$ b $

  A呈现B,呈现C 

当B呈现C时,我想要B被驳回,所以我唯一的视图控制器是A和C.我不知道在哪里调用:

  [self dismissModalViewControllerAnimated:NO]; 



我创建了一个委托模式,在B之后出现C,A会关闭B,但没有什么被解雇。



如果B是C的委托,那么C会自动关闭。

解决方案

我想你可以使用NSNotificationCenter。
你可以在B调用一个NSNotificationCenter,调用一个方法来关闭自己,然后通过C发送通知,调用B的NSNotificationCenter。



 <$> 



c $ c> [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissFunction :) name:@DismissFunctionobject:nil];

,方法如下:

   - (void)dismissFunction:(NSNotification *)notification 
{
[self.navigationController dismissModalViewControllerAnimated:YES];
}

在C中添加:


$ b b

  [[NSNotificationCenter defaultCenter] postNotificationName:@DismissFunctionobject:nil]; 


View Controller A presents View Controller B modally, which has a button to present View Controller C modally.

Here is my flow:

A presents B which presents C

When B presents C, I want B to be dismissed, so my only view controllers are A and C. I am not sure where to call:

[self dismissModalViewControllerAnimated:NO];

in order to dismiss B.

I created a delegation pattern, where right after B presents C, A will dismiss B however nothing gets dismissed.

If B is C's delegate then C dismisses itself.

解决方案

I think you can use NSNotificationCenter. You can make a NSNotificationCenter at B that calling a method to dismiss itself, then make a post Notification from C to call the NSNotificationCenter at B.

I'm not sure of it, but it may works.

In B add:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissFunction:) name:@"DismissFunction" object:nil];

and the method like this:

- (void)dismissFunction:(NSNotification*)notification
{
      [self.navigationController dismissModalViewControllerAnimated:YES];
}

And in C add:

[[NSNotificationCenter defaultCenter] postNotificationName:@"DismissFunction" object:nil];

这篇关于关闭模式视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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