Ios 模态窗口未被解除
我有两个通过编程创建的按钮,您可以在viewDidLoad方法中看到。在模式窗口中,我有一个按钮,通过委托调用cancelSearch方法。当我在cancelSearch方法上放置断点时,它被命中,因此我知道我的委托设置正确,但即使它调用此行[self dismissViewControllerAnimated:YES completion:nil];它实际上并没有关闭模式窗口 下面的代码都来自我的主控制器视图Ios 模态窗口未被解除,ios,ios5,delegates,modalviewcontroller,Ios,Ios5,Delegates,Modalviewcontroller,我有两个通过编程创建的按钮,您可以在viewDidLoad方法中看到。在模式窗口中,我有一个按钮,通过委托调用cancelSearch方法。当我在cancelSearch方法上放置断点时,它被命中,因此我知道我的委托设置正确,但即使它调用此行[self dismissViewControllerAnimated:YES completion:nil];它实际上并没有关闭模式窗口 下面的代码都来自我的主控制器视图 - (void)viewDidLoad { [super viewDidLo
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *actionButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(showActionMenu:)];
actionButton.style = UIBarButtonItemStyleBordered;
UIBarButtonItem *searchButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(showSearchMenu:)];
searchButtonItem.style = UIBarButtonItemStyleBordered;
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 103.0f, 44.01f)];
NSArray* buttons = [NSArray arrayWithObjects:actionButton, searchButtonItem, nil];
[toolbar setItems:buttons animated:NO];
self.navigationItem.title = @"Census Management";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
[[RKClient sharedClient] get:@"censusmanagement" delegate:self];
}
- (IBAction)showActionMenu:(id)sender
{
[self performSegueWithIdentifier: @"CMActionSegue" sender: self];
}
- (IBAction)showSearchMenu:(id)sender
{
ehrxCMSearchView *search = [[self storyboard] instantiateViewControllerWithIdentifier:@"cmSearch"];
search.selectedOptions = self.selectedOptions;
search.delegate = self;
[self.navigationController pushViewController:search animated:YES];
}
- (void)cancelSearch:(ehrxCMSearchView *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}
如果视图控制器以模式显示,则应使用以下选项:
[self.presentingViewController dismissModalViewControllerAnimated:YES];
presentingViewController属性仅在iOS 5中可用。因此,如果您针对的是较旧版本的iOS,则必须改用self.parentViewController(为每个iOS版本使用相应的控制器,您必须处理此问题)
如果在父视图/演示视图控制器中创建此控件,则只需调用此控件:
[self dismissModalViewControllerAnimated:YES];
如果视图控制器以模式显示,则应使用以下选项:
[self.presentingViewController dismissModalViewControllerAnimated:YES];
presentingViewController属性仅在iOS 5中可用。因此,如果您针对的是较旧版本的iOS,则必须改用self.parentViewController(为每个iOS版本使用相应的控制器,您必须处理此问题)
如果在父视图/演示视图控制器中创建此控件,则只需调用此控件:
[self dismissModalViewControllerAnimated:YES];
您可以使用类似于以下内容的方式取消模式视图:
[self dismissModalViewControllerAnimated:YES];
[self presentModalViewController:search animated:YES];
这将取消使用类似以下内容加载的模态视图:
[self dismissModalViewControllerAnimated:YES];
[self presentModalViewController:search animated:YES];
但是,在查看代码段时,似乎正在使用以下行将“搜索视图”控制器推送到导航堆栈上:
[self.navigationController pushViewController:search animated:YES];
因此,我认为您可能需要从导航堆栈中弹出视图,而不是将其视为模式视图:
[self.navigationController popViewControllerAnimated:YES];
您可以使用类似于以下内容的方式取消模式视图:
[self dismissModalViewControllerAnimated:YES];
[self presentModalViewController:search animated:YES];
这将取消使用类似以下内容加载的模态视图:
[self dismissModalViewControllerAnimated:YES];
[self presentModalViewController:search animated:YES];
但是,在查看代码段时,似乎正在使用以下行将“搜索视图”控制器推送到导航堆栈上:
[self.navigationController pushViewController:search animated:YES];
因此,我认为您可能需要从导航堆栈中弹出视图,而不是将其视为模式视图:
[self.navigationController popViewControllerAnimated:YES];
根据其他人告诉我的,使用委托是首选方法,所以我正尝试这样做。这也很有帮助,因为我想将数据从模态控制器传递回主控制器。这两种方法在iOS 6.0中都被贬低了。根据其他人告诉我的,使用委托是首选方法,所以我尝试这样做。这也很有帮助,因为我想把数据从模态控制器传回主控制器。这两种方法在iOS 6.0中都被贬低了。我想你是对的。我更改了它,因为我正在传递数据。所以我现在这样做的话,我想它已经不再是一个模态视图了。既然我已经设置了代理,我可以从主视图控制器进行设置吗?你的最后一行看起来像是我将从我展示的新视图中执行的。仔细想想,我想,因为我推动视图,而不是将其视为模态,我应该能够将数据传回主控制器,并从主控制器手动调用返回函数,对吗?@Jhorra您可以从主视图控制器或新视图控制器调用-popViewControllerAnimated:因为它们(理论上)应该使用相同的UINavigationController。对于模态视图,您需要从显示模态视图控制器(很可能是您的主视图控制器)的视图中调用-dismissModalViewControllerAnimated。我最终改变了使用segue并使用prepareforsgue传递数据的方式。我想您是对的。我更改了它,因为我正在传递数据。所以我现在这样做的话,我想它已经不再是一个模态视图了。既然我已经设置了代理,我可以从主视图控制器进行设置吗?你的最后一行看起来像是我将从我展示的新视图中执行的。仔细想想,我想,因为我推动视图,而不是将其视为模态,我应该能够将数据传回主控制器,并从主控制器手动调用返回函数,对吗?@Jhorra您可以从主视图控制器或新视图控制器调用-popViewControllerAnimated:因为它们(理论上)应该使用相同的UINavigationController。对于模态视图,您需要从显示模态视图控制器(很可能是您的主视图控制器)的视图中调用-dismissModalViewControllerAnimated。我最终改变了使用segue的方式,并使用prepareforsgue传递数据。