iPhone App开发人员-从View Controller加载视图 [英] iPhone App Dev - Loading View From View Controller

查看:96
本文介绍了iPhone App开发人员-从View Controller加载视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个调查表viewcontroller类.这将实例化几个questionviewcontrollers(每个questionviewcontroller有一个关联的视图).

I have a questionnaire viewcontroller class. This instantiates several questionviewcontrollers (each questionviewcontroller has an associated view).

我如何获取问卷以加载与他们的问题视图控制器相关的这些问题视图....

How do I get the questionnaire to load these question views associated with their questionviewcontrollers....

-(void) setQuestions{
    for (NSDictionary *q in self.questions) {       
        /* Create our Question object and populate it */
        QuestionViewController *question = [[QuestionViewController alloc]init];        
        [question setQuestionId:[q objectForKey:@"questionId"] withTitle:[q objectForKey:@"question"] number:[q objectForKey:@"questionNumber"] section:[q objectForKey:@"sectionId"]];
        /* Add it to our question (mutable) array */
        [questionArray addObject:question];
        [question release];
    }
}

以上方法在QuestionnaireViewController的viewDidLoad方法中调用,并在其中创建QuestionViewControllers.每个人都有一个带有下一个按钮的关联视图.

The above method is called in the viewDidLoad method of the QuestionnaireViewController and is where the QuestionViewControllers are created. Each one has an associated view with a next button.

推荐答案

不清楚您的问题是什么意思,当您说我如何获得问卷以加载这些问题视图"时.

It's not clear from your question what you mean when you say, "How do I get the questionnaire to load these question views".

您只是问问选择问题时如何显示QuestionViewController吗?如果是这样,这听起来像一个基于导航的应用程序.通常,您将UINavigationController用作应用程序委托中的顶级视图控制器,将QuestionaireViewController设置为UINavigationController的rootViewController.然后,当用户在QuestionaireViewController中选择一个问题时,可以使用以下命令显示其控制器:

Are you just asking how to display a QuestionViewController when a question is selected? If so, this sounds like a navigation based application. You would typically use a UINavigationController as your top level view controller in your app delegate, setting your QuestionaireViewController as the rootViewController of your UINavigationController. Then, when the user selects a question in your QuestionaireViewController, you can display its controller using:

[self.navigationController pushViewController:questionViewController animated:YES];

如果相反,您问的是如何将这些QuestionViewControllers的视图显示为QuestionaireViewController的子视图,则简短的答案是不这样做(至少不是在iOS 4.x下). Apple的视图控制器框架并非旨在支持使用嵌套视图控制器来同时管理多个子视图.文档指出,每个视图控制器应对应于iPhone上的一个全屏视图. iPad会针对分割视图和弹出窗口等内容略微更改这些规则,但它仍然不能让您将视图控制器嵌套在自己的自定义视图控制器中.

If instead you're asking how you can display the views for these QuestionViewControllers as subviews of your QuestionaireViewController, the short answer is don't do it (at least not under iOS 4.x). Apple's view controller framework is not designed to support using nested view controllers to manage multiple subviews simultaneously. The documentation states that each view controller should correspond to one full-screen view on iPhone. iPad changes these rules slightly for things like split views and popovers, but it's still not designed to let you nest view controllers within your own custom view controllers.

(实际上,从技术上讲,可以使用多个视图控制器来在单个屏幕上管理不同的子视图,但是要正确地做到这一点,则需要掌握视图控制器框架的设计方面的专业知识,以便您可以正确地委派所有各种UIViewController方法以及诸如viewWillAppear:,navigationController,tabBarController之类的属性.通常最好遵循Apple的建议,并在每个屏幕上使用一个视图控制器.)

(In truth it is technically possible to use multiple view controllers to manage different subviews on a single screen, but doing so properly requires expert knowledge of how the view controller framework is designed so that you can properly delegate all the various UIViewController methods and properties like viewWillAppear:, navigationController, tabBarController, etc. You're generally better off following Apple's advice and using one view controller per screen.)

这篇关于iPhone App开发人员-从View Controller加载视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆