Iphone创建一个自定义UIobject [英] Iphone create a custom UIobject

查看:97
本文介绍了Iphone创建一个自定义UIobject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于负面评论,我只是小步骤地简化了我的问题;

Regarding on negative comments here I simplfy my question in small steps;

我有一个基于视图的应用程序,它与Web服务通信并重新获取xml,解析xml并将其竞争映射到适当的视图组件(例如,如果这是一个日期显示问题使用datepicker,如果问题有2个值显示带有分段控件,如果更多带有pickerview..etc)那么它是一个有很多页面的动态问题。

I have a view based application which communicates with a web service and recives xml, parse xml and map its contens an appropriate view component (e.g if thats a date show the question with datepicker, if question has 2 values show it with a segmented control, if more with a pickerview..etc) so its a dynamic questionary with many pages.

1-应用程序接收XML

1-App Receive XML

2-Parse XML并获取最新未解答的问题(每页可以有无限数量的问题),每个问题都需要询问根据问题类型,文本框或选取器视图或分段控件,也可能需要一些标签进行说明,验证警报和问题标签。每个问题和标签应该有不同的字体和颜色,用xml定义。

2-Parse XML and get the latest un-answered questions (there can be unlimited number of questions per each page), each question need to be asked with either a textbox or picker view or segmented control depending on the question type, also it may need a few labels for explanition, and validation alerts, and the question label. Each question and label should have different fonts and colors, defined in xml.

3-用户回答页面中的所有问题,然后按发送按钮。

3- User answers all questions inhe page and press send button.

4-Web服务接收,检查答案并根据给出的答案发回新问题。

4-Web service receives, checks the answers and sends back new question(s) to be asked depending on the answers given.

5 -APP接收新的XML(每个XML包括整个状态,即所有以前回答的问题)并解析以找出最新的未答复的问题。

5-APP receives new XML (each XML includes whole the state i.e all the previous answered questions) and parse to find out the latest unanswered questions.

6 - 用户再次回答和发送问题并等待下一组问题直到没有问题要求

6-User again answers and sends the questions and wait for the next set of questions until there are no questions to be asked

7-OR用户可能想要返回并编辑前几页中的一些问题。但如果他编辑了之前页面中的任何问题,那么在该页面之后回答的页面将不再有效,因为每组问题服务器发送取决于先前回答的问题,因此需要从XML中删除所有后续问题并发送回请求好像是等待回复的最新页面。

7-OR user may want to go back and edit some questions in previous pages. BUT if he edits any question in previous pages then the pages answered after that page are not valid anymore, because each set of question server sends depends on the previosly answered questions, so it needs to delete all the later questions from XML and sends back a request as if it was the latest page waiting for a response.

问题;

我想创建一个问题对象是完全可定制的,包括可能的必要UI组件(文本框或日期选择器或选择器和一些标签及其可见选项和颜色),并根据问题类型创建该对象,并将该对象插入UIscrollview或表视图。那么如何定义这个对象的类呢?它应该是UIview类的子类吗?我应该把它的delegete方法放在哪里?

I want to create a question object which is totaly customazible and includes the possible necessary UIcomponents(textbox OR datepicker OR picker AND some labels with their visibilty options, and colors) and create that object depending on the question type, and insert that object to the UIscrollview or Table view. So how can I define this object's class? should it be a subclass of a UIview class? and where should I put its delegete methods?

谢谢!

推荐答案

如果您认为可以提前设计每种类型的问题,请为每个问题做一个xib。如果它们彼此太不相同,请创建一个动态组合视图的构建器类。请注意,在任何情况下,您都必须使用代码将视图上的控件链接到视图控制器。

If you think you can design each type of question in advance, do a xib for each. If they are too different from each other, make a builder class that dynamically composes the view. Note that in any case you will have to use code to link the controls on the view to the view controller.

如果您使用的是表格,则返回的视图将作为表格单元格使用,但我认为您不应该在表格中放置日期选择器。表基本上是一个列表,而不是一个屏幕容器。导航控制器听起来更好。你应该检查类似的应用程序以获得灵感。

If you are using a table, the view returned will work as the table cell but I don't think you should put a datepicker inside a table. A table is basically a list, not a screen container. A navigation controller sounds better for that. You should check similar applications for inspiration.

关于单元测试的一些非正式的话......(如果你已经知道单元测试,你可以跳过其余的帖子)。 ..

A few offtopic words about unit testing... (you can skip the rest of the post if you already know unit testing)...

即使你正在构建一个完整的应用程序,如果你单独处理每个独立的任务,OO设计最有效,因为它强制实现解耦,这是一个复杂应用程序的重要目标。

Even when you are building a whole app, OO design works best if you work on each of the independent tasks in isolation, because it enforces decoupling, which is an important goal on a complex app.

大多数程序员使用单元测试来驱动小的非UI相关代码。单元测试是一小段代码,用于执行和测试另一段代码的结果。它通常在 GHUnit 等框架的帮助下,在您内部的单独目标上执行项目。

Most programmers use unit testing to drive small non UI related code. A unit test is a small piece of code that executes and test the result of another piece of code. It is usually executed with the help of a framework, like GHUnit, on a separate target inside your project.

例如:这是GHUnit中的一个虚构测试方法,用于测试问题解析器是否正常工作。

eg: this is an imaginary test method in GHUnit to test if your question parser works correctly.

// is my parser working correctly?
- (void) testDocument {
    File *xmlFile = [File alloc] initWithFilename:@"sampleQuestion.xml"];
    Question *question = [QuestionParser parse:xmlFile];
    GHAssertTrue(question!=nil);
}

如果您的代码通过了测试,那么这是朝着正确方向迈出的坚实一步。而且您不必担心让整个应用程序正在解决此特定任务。

If your code passes the test, that's a solid step in the right direction. And you didn't have to worry about getting the whole app working to solve this specific task.

如果你现在没有看到单元测试的重点,那就忘了它,当你准备就绪时它会有意义。

If you don't see the point of unit testing now, forget about it, it will make sense when you are ready.

这篇关于Iphone创建一个自定义UIobject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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