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

前端之家收集整理的这篇文章主要介绍了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
   // 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的新类,导入它的标题,创建它的实例,并将其推送到导航控制器上.

猜你在找的Xcode相关文章