On Sep 1, 2015, at 11:46 PM, Quincey Morris < email@hidden> wrote:
On Sep 1, 2015, at 20:05 , Ken Thomases < email@hidden> wrote:
As I said, this isn't a show-stopping problem, it's just odd to pull view controlling code *out* of my view controller and put it somewhere else.
Well, if the code needs to change which window is key, which views are present/active within that window, and then which control has focus, then it isn't really view-controlling code. It's much more global than that.
It’s probably worth being explicit that there are 2 kinds of UI that might apply here.
I should've said. The app is a single window with a text field, a table, and (eventually) a few other controls. I'll need a prefs window, a login window, and a few others in time, but it's not document-based. The menu items I'm currently trying to get working either move focus to the text field, or act on data held in the table, possibly putting up alerts if something goes wrong, or animating progress indicators in the main window. Again, eventually some menu items may open other windows as well.
1. If this is something like a document app, where the view controller implements the document view (and storyboards will tend to encourage putting the view logic here, instead of in the window controller as was more usual in the old days, if for no other reason than analogy to iOS), then the menu item is likely enabled only when the view controller is in the responder chain. In that case, the action method should be in the view controller, even though it’s no longer possible to wire up the target directly in IB.
2. If the menu item really is global, in the sense that it causes a pre-determined window to be brought to the front if necessary, before making a text field first responder, then the action method should be in the app delegate, and this should deal with the activation logic, even if it hands off control to the view controller eventually.
Handing off control would be good, that way I could use appDelegate as a kind of entry point but keep most of my logic (and outlets) in the view controllers where they belong. Hopefully I can work out how to do just that; I imagine the appDelegate has a way of accessing the view controller, it's just a matter of finding out how.
By chance, your response was couched mostly in terms of #2, while mine was mostly #1. It may have seemed like we were making conflicting recommendations about where to put the action method, but there’s really no conflict. There are just different answers, depending on the app design.
|