如何将多个视图控制器推送到导航控制器上
新手在这里编程我的第一个应用程序(做了几个教程应用程序)。 我正在使用称为“RootViewController”的视图控制器作为导航控制器。 我已经使用以下命令成功地将另一个视图控制器放在了名为“ClientListViewController”的顶部:
[self.navigationController pushViewController:clientListViewController animated:YES];
我现在在ClientListViewController,并试图推动另一个视图控制器到名为“AddClientViewController”的堆栈。 我想以UIModalPresentationFormSheet的forms使这个模态视图控制器。 我试图使用上面的命令的变种推新视图控制器,但我不知道如何取代“自我”。 我努力了:
[RootViewController.navigationController pushViewController:AddClientViewController animated:YES];
和…
[[RootViewController navigationController] pushViewController:AddClientViewController animated:YES];
以及这些组合中的每一个都使用小的“R”来表示Root。 仍然没有运气。
为了清楚起见,我在我的实现文件的顶部使用了下面的代码。
#import "AddClientViewController.h"
我是以正确的方式处理这个问题,还是应该使用全新的导航控制器将其添加到?
任何指针大大收到。
非常感谢
每个UIViewController
都有一个名为navigationController
的属性。 如果有的话,这个属性引用最近的包围UINavigationController
。 所以你可以只在你的ClientListViewController
说self.navigationController
。
在iOS中,我们通常将类名称大写。 所以这听起来像AddClientViewController
是一个类名称。 您需要将该类的实例推送到导航控制器的堆栈上。 像这样的东西:
AddClientViewController *addClientVC = [[AddClientViewController alloc] init]; [self.navigationController pushViewController:addClientViewController animated:YES];
在推送之前,您可能需要使用不同的init方法或设置addClientVC
某些属性; 这取决于你的AddClientViewController
的实现。
如果您想以模态方式呈现,则不要将其推到导航控制器的堆栈上。 相反,你这样做:
AddClientViewController *addClientVC = [[AddClientViewController alloc] init]; addClientVC.modalPresentationStyle = UIModalPresentationFormSheet; [self presentViewController:addClientVC animated:YES completion:nil];
- 使用Swift结构的简单iOS / macOS应用配置
- HTML电子邮件丢失在iPhone上太长时间格式化
- -canOpenURL:URL失败:“spotify:” – 错误:“(null)”
- 有像iOS的JUNG的可视化框架?
- 无法指定types'(String?,Bool,?,NSError?) – >()'的值
- 使用UIPageViewController和UISegmentedControl进行平滑过渡,就像在Apple Music App中一样
- IOS模拟器问题的应用程序只运行时,第二次启动..
- 调整UISearchDisplayController灰色黑色覆盖
- 应用程序崩溃与EXC_BREAKPOINT错误