iOS   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了objective-c – 以模态方式呈现视图控制器 – iPad大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我发现这段代码显示了一个模态视图: - (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 // navigatio
我发现这段代码显示一个模态视图:

- (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方法中复制此代码以使其工作,我还需要做些什么吗?

感谢并抱歉所有问题.

解决方法

方法定义为IBACtion,如 – (IBACtion)add:(id)sender并在界面构建器中将按钮的内部事件绑定到视图控制器对象的add:action outlet.

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

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

大佬总结

以上是大佬教程为你收集整理的objective-c – 以模态方式呈现视图控制器 – iPad全部内容,希望文章能够帮你解决objective-c – 以模态方式呈现视图控制器 – iPad所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。