Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 模态视图控制器未调用呈现视图控制器';s dismissModalViewControllerAnimated:方法_Ios_Uiviewcontroller_Uikit_Modal Dialog - Fatal编程技术网

Ios 模态视图控制器未调用呈现视图控制器';s dismissModalViewControllerAnimated:方法

Ios 模态视图控制器未调用呈现视图控制器';s dismissModalViewControllerAnimated:方法,ios,uiviewcontroller,uikit,modal-dialog,Ios,Uiviewcontroller,Uikit,Modal Dialog,在模态视图控制器中,我有一个按钮处理方法,包括 [self dismissModalViewControllerAnimated: YES]; 在显示视图控制器中,我覆盖dismissModalViewControllerAnimated:如下所示: -(void) dismissModalViewControllerAnimated: (BOOL)animated { NSLog(@"dismiss"); [super dismissModalViewControllerAnimat

在模态视图控制器中,我有一个按钮处理方法,包括

[self dismissModalViewControllerAnimated: YES];
在显示视图控制器中,我覆盖dismissModalViewControllerAnimated:如下所示:

-(void) dismissModalViewControllerAnimated: (BOOL)animated
{
  NSLog(@"dismiss");
  [super dismissModalViewControllerAnimated: animated];
}
触摸按钮时,会调用按钮处理方法,但似乎不会调用dismissModalViewControllerAnimated:override:NSLog(@“Dismise”);语句,并且方法内的断点不会被命中

我试过了

[[self presentingViewController] dismissModalViewControllerAnimated: YES];
但这也不起作用。但是,模态视图控制器确实会被取消


知道可能出了什么问题吗?

这通常是通过将演示视图控制器声明为模态视图控制器的委托来处理的。然后,模态VC调用呈现VC中的委托方法来消除它创建的模态转换

例如:

模态VC.h:

@protocol ModalViewControllerDelegate
-(void)dismissMyModalViewController;
@end
模态VC.m:

// When you want to dismiss the Modal VC
[delegate dismissMyModalViewController]; 
介绍VC.h:

// Make sure to #import ModalVC.h
@property (nonatomic, retain) id <ModalViewControllerDelegate> delegate;

这通常通过将呈现视图控制器声明为模态视图控制器的委托来处理。然后,模态VC调用呈现VC中的委托方法来消除它创建的模态转换

例如:

模态VC.h:

@protocol ModalViewControllerDelegate
-(void)dismissMyModalViewController;
@end
模态VC.m:

// When you want to dismiss the Modal VC
[delegate dismissMyModalViewController]; 
介绍VC.h:

// Make sure to #import ModalVC.h
@property (nonatomic, retain) id <ModalViewControllerDelegate> delegate;

表示模态视图控制器的代码包含在UIViewController中,而UIViewController又包含在UINavigationController中。当我打电话的时候

[[self presentingViewController] dismissModalViewControllerAnimated: YES];


正在将取消消息发送到UINavigationController对象。

表示模式视图控制器的代码包含在UIViewController中,而UIViewController又包含在UINavigationController中。当我打电话的时候

[[self presentingViewController] dismissModalViewControllerAnimated: YES];

正在将解雇消息发送到UINavigationController对象。

来自:

在iPad上,当呈现的视图控制器的modalPresentationStyle为UIModalPresentationCurrentContext时,必须决定哪个视图控制器应该是呈现的视图控制器的presentingViewController。这将确定显示的视图控制器的视图将替换哪个视图。此决定涉及另一个UIViewController属性DefinePresentationContext(BOOL)。从向其发送presentViewController:animated:completion:的视图控制器开始,我们沿着父视图控制器链走,查找DefinePresentationContext属性为YES的视图控制器。如果我们找到一个,那就是那个;它将是presentingViewController,其视图将被显示的视图控制器的视图替换。如果我们找不到一个,事情就好像显示的视图控制器的modalPresentationStyle是UIModalPresentationFullScreen

TL;DR
1.在所需的
presentingViewController上,将
definesPresentationContext
设置为true
2.在所需的
presentedViewController

上,将
modalPresentationStyle
设置为
UIModalPresentationCurrentContext

在iPad上,当呈现的视图控制器的modalPresentationStyle为UIModalPresentationCurrentContext时,必须决定哪个视图控制器应该是呈现的视图控制器的presentingViewController。这将确定显示的视图控制器的视图将替换哪个视图。此决定涉及另一个UIViewController属性DefinePresentationContext(BOOL)。从向其发送presentViewController:animated:completion:的视图控制器开始,我们沿着父视图控制器链走,查找DefinePresentationContext属性为YES的视图控制器。如果我们找到一个,那就是那个;它将是presentingViewController,其视图将被显示的视图控制器的视图替换。如果我们找不到一个,事情就好像显示的视图控制器的modalPresentationStyle是UIModalPresentationFullScreen

TL;DR
1.在所需的
presentingViewController上,将
definesPresentationContext
设置为true

2.在所需的
presentedViewController

上,将
modalPresentationStyle
设置为
UIModalPresentationCurrentContext
,该委托属性在哪里,它实现了什么协议?在UIViewController、UIResponder或NSObject中找不到委托属性。您可以添加自己的委托方法,而不是委托属性。我将在答案中提供一个粗略的例子。请稍等,谢谢你抽出时间回答。我明白你现在说的话,但我不明白重点。向模态VC传递指向当前VC的指针似乎是一种复杂的方式。在任何情况下,您都可以从我的回答中看到,问题在于解雇消息被发送到导航控制器,而不是它所包含的UIViewController。@StephenAshley.developer EIJay建议使用代理的方式是苹果公司推荐的处理解雇模式VC的方式,允许演示VC知道它何时被取消。委托属性在哪里,它实现了什么协议?在UIViewController、UIResponder或NSObject中找不到委托属性。您可以添加自己的委托方法,而不是委托属性。我将在答案中提供一个粗略的例子。请稍等,谢谢你抽出时间回答。我明白你现在说的话,但我不明白重点。向模态VC传递指向当前VC的指针似乎是一种复杂的方式。在任何情况下,您都可以从我的回答中看到,问题在于解雇消息被发送到导航控制器,而不是它所包含的UIViewController。@StephenAshley.developer EIJay建议使用代理的方式是苹果公司推荐的处理解雇模式VC的方式,让在场的VC知道什么时候被解雇。