加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 以模态方式呈现视图控制器 – iPad

发布时间:2020-12-14 17:36:13 所属栏目:百科 来源:网络整理
导读:我发现这段代码显示了一个模态视图: - (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
我发现这段代码显示了一个模态视图:

- (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”来解决这个问题?

我在头文件中作为委??托放了什么?我需要在其他地方设置吗?喜欢财产?

一旦我在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并在界面构建器中将按钮的内部事件绑定到视图控制器对象的add:action outlet.

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您通常需要更改标头以添加方法,添加实例变量或包含自定义类.但是,您可能需要在某处(在标题或实现文件中)使用#import RecipeAddViewController.h才能使用该类.对于要在另一个文件中使用的任何自定义类,都是如此.

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

将其替换为要推送的视图控制器类. UIViewController本身很少有用.它是为子类化的.因此,您创建一个继承自UIViewController的新类,导入它的标题,创建它的实例,并将其推送到导航控制器上.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读