gpt4 book ai didi

objective-c - 模态呈现 View Controller - iPad

转载 作者:搜寻专家 更新时间:2023-10-30 19:43:14 25 4
gpt4 key购买 nike

我发现这段代码显示模态视图:

- (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 提供了这个但没有头文件所以我不知道是否应该有任何东西?

代码引用了 RecipieAddViewController 我应该用什么来替换它,“UIViewController”?

我将什么作为委托(delegate)放入头文件中?我需要在其他地方设置吗?喜欢属性(property)?

在我的 buttonPress 方法中复制这段代码以使其工作后,我还需要做些什么吗?

感谢并抱歉提出所有问题。

最佳答案

My question is how do I implement this code (I'm going to place it in a buttonPress method)

将方法定义为 IBAction,例如 -(IBAction)add:(id)sender 并在界面生成器中绑定(bind)按钮的 touch up inside 事件到 View Controller 对象的 add: Action 导出。

Do I need to define anything in my header file? The bit that confuses me is that apple on provides this and no header file so i cant tell if anything should be there?

没有。所有这些东西都需要 UIKit.h 您通常需要更改 header 以添加方法、添加实例变量或包含自定义类。但是,您可能需要在某处(在您的 header 或实现文件中)#import RecipeAddViewController.h 才能使用该类。对于您编写的要在另一个文件中使用的任何自定义类都是如此。

The code refers to RecipieAddViewController what do I repleace this with, "UIViewController"?

将其替换为您要推送的 View Controller 类。 UIViewController 本身很少有用。它被子类化了。因此,您创建了一个继承自 UIViewController 的新类,导入它的 header ,创建它的实例,然后将它推送到导航 Controller 上。

关于objective-c - 模态呈现 View Controller - iPad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2324650/

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