开发者

Writing a new delegate object vs using a view controller as the delegate

This is more a question of what is generally good practice in iPhone coding.

I have a scroll view with UISegmen开发者_如何学CtedControls, submit buttons, UIActionSheets, zooming, and close buttons that show temporarily.

Should I just be piling all of the method calls (target-action for UIControls) (which are not really formal delegate methods) and zooming delegate methods for UIScrollViews into this one view controller? Or would it better practice to create a new [delegate] object to handle the functionality of these.


I think, best place for all this is a view controller.

My idea is that according to MVC model, managing UIControl's action or some zooming is neither a work with data (M) or some displaying (V), so there is only one place for this - controller (C).

Of course if some UIControl event causes data-management, you should (ideologically) do it in model, but model methods should be called from controller anyhow. I think it's not the best way to make direct connection view<->model.


It depends on what you need. The idea of delegate encourage people to create a new class to handle more.But in most of cases, it's convenient to implement the delegate methods in the view controller.For example, you might want to use instance variables in the delegate methods.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜