【问题标题】:Presenting a view controller modally - iPad以模态方式呈现视图控制器 - iPad
【发布时间】:2011-01-20 10:42:03
【问题描述】:

我发现这段代码可以显示一个模态视图:

- (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 方法中添加了这段代码后,我还需要做什么才能使其工作吗?

感谢和抱歉所有问题。

【问题讨论】:

    标签: objective-c iphone xcode uiview ipad


    【解决方案1】:

    我的问题是如何实现这段代码(我将把它放在 buttonPress 方法中)

    将方法定义为IBAction,如-(IBAction)add:(id)sender,并在界面构建器中将按钮的touch up inside 事件绑定到视图控制器对象的add: 操作出口。

    我需要在头文件中定义任何内容吗?让我困惑的一点是,apple on 提供了这个并且没有头文件,所以我不知道是否应该有任何东西?

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

    代码指的是 RecipieAddViewController 我用什么来代替它,“UIViewController”?

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

    【讨论】:

    • 非常感谢,您的回复非常好,并且澄清了很多 :)
    猜你喜欢
    • 1970-01-01
    • 2020-11-24
    • 2014-01-20
    • 1970-01-01
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多