开发者

Iphone create a custom UIobject

开发者 https://www.devze.com 2023-03-18 22:20 出处:网络
Regarding on negative comments here I simplfy my question in small steps; I have a view based application which communicates with a web service and recives xml, parse xml and map its contens an appr

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

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-App Receive 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开发者_Go百科 the question label. Each question and label should have different fonts and colors, defined in xml.

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

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

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-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 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.

Question;

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?

Thanks!


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)...

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.

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.

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.


This would probably be a subclass of UITableViewCell. You might want to make an NSObject subclass for the question its self and load it into the custom cell.

0

精彩评论

暂无评论...
验证码 换一张
取 消