开发者

is it good practice to share the ADD and EDIT screen to use the same UIViewController?

is it good practice to share the ADD and EDIT screen to use the same UIViewController?

That is in the case where the only real difference would be in one the values would be populated with existing (EDIT).

PS. Some clarification. So perhaps take the simple case where there is just one or two NSString fields (e.g. title & description) - so is there anything wrong (e.g any gottchas) associ开发者_运维百科ated with using the same controller/NIB(view) for both EDIT and ADD?


Not sure about "good practise", but...

Populating a Label with one or another string is easy, also easy is hiding buttons or fields on depending if the ADD or EDIT view is displayed.

The problems tend to come when your view has received the user input and then needs to decide whether to modify an existing object or to create a new object.

So before exiting, the view has to decide how to treat user input. If the differentiation is mind boggling complex you are better off with two viewsControllers. If it is a matter of a simple if-the-else in or near the viewWillDisapper method then one view can do.


I would use inheritance in this case. Some base UIViewController and two additional UIViewControllers - one for add, second for editing. You can use one UIViewController too, but it depends on how difficult your task is or isn't. It's too general question.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜