示意一个视图控制器 - iPad
-
22-09-2019 - |
题
我发现此代码显示模式视图:
- (void)add:(id)sender {
// Create the root view controller for the navigation controller
// The new view controller configures a Cancel and Done button for the
// navigation bar.
RecipeAddViewController *addController = [[RecipeAddViewController alloc]
initWithNibName:@"RecipeAddView" bundle:nil];
addController.delegate = self;
// Create the navigation controller and present it modally.
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];
// The navigation controller is now owned by the current view controller
// and the root view controller is owned by the navigation controller,
// so both objects should be released to prevent over-retention.
[navigationController release];
[addController release];
}
我的问题是如何实现此代码(我将其放置在ButtonPress方法中)
我需要在标题文件中定义任何内容吗?让我感到困惑的一点是,Apple On提供了此功能,没有标题文件,所以我无法分辨是否应该有什么?
该代码是指felectieaddviewController我该用“ uiviewController”来补充什么?
我将作为代表在headerfile中置于什么?我需要在其他任何地方进行设置吗?喜欢有财产吗?
一旦我在ButtonPress方法中使用此代码以使其正常工作,我还需要做其他事情吗?
谢谢,很抱歉所有问题。
解决方案
我的问题是如何实现此代码(我将其放置在ButtonPress方法中)
将方法定义为 IBAction
喜欢 -(IBAction)add:(id)sender
在接口中,构建器绑定了一个按钮 touch up inside
事件到视图控制器对象的事件 add:
动作插座。
我需要在标题文件中定义任何内容吗?让我感到困惑的一点是,Apple On提供了此功能,没有标题文件,所以我无法分辨是否应该有什么?
没有。所有这些东西都需要 UIKit.h
通常,您需要更改标题以添加方法,添加实例变量或包括自定义类。您可能需要一个 #import RecipeAddViewController.h
但是,(在标题或实现文件中)的某个地方以使用该类。对于要在另一个文件中使用的任何自定义类都是正确的。
该代码是指felectieaddviewController我该用“ uiviewController”来补充什么?
将其替换为要推开的视图控制器类。 UIViewController
本身很少有用。它是分类的。因此,您创建了一个从继承的新类 UIViewController
, ,导入其标题,创建和实例,然后将其推到导航控制器上。