gpt4 book ai didi

iphone - 在 iPad 中从左侧 View Controller 呈现模态视图

转载 作者:行者123 更新时间:2023-11-29 04:12:54 26 4
gpt4 key购买 nike

我在我的项目中实现了分割 View 。我的左侧 View 包含一个表格 View 和一个按钮。

单击该按钮,我将呈现模态视图。

在横向模式下工作正常,但对于纵向模式, View 显示与左侧框架 View 相同,而不是全屏。

它也适用于 ios6 的横向和纵向模式。

最佳答案

您可以在详细信息 View Controller 中注册通知,然后在需要显示模态视图 Controller 时从根目录发布通知。

假设您正在使用 ARC。在拆分 Controller 中,左侧 View Controller 称为根 Controller ,右侧 View Controller 称为详细 Controller 。

在您的详细 Controller 中,您需要实现代码来注册和删除通知。

- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(displayModalController) name:@"DisplayModalControllerNotification" object:nil];

}

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)displayModalController {

UIViewController *myController = [[UIViewController alloc] initWithNibName:@"MyController" bundle:nil];
[self presentViewController:myController animated:YES completion:^{
// code to be executed after completition
}];
}

现在,将此代码放在根 Controller 中后,您只需使用以下代码行即可在需要时调用它:

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

这是基本示例,可根据您的需要进行修改,例如,如果您需要在初始化时发送一些带有通知的对象,以将其传递到模态视图 Controller 等。

关于iphone - 在 iPad 中从左侧 View Controller 呈现模态视图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14152496/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com