iPhone OS Utility App - Flipside View and Main Vie

2019-05-14 15:55发布

问题:

I am currently working on an iPhone 2.1 application. I am new to Objective C, coming from a Java background.

My application has as a base the Utility Application template available in Xcode with the iPhone SDK. Currently I have some controls, such as an UISlider and text box, in the FlipsideView. The UISlider already has a method which is being called when the value changes, using targets and selectors. However, I would also like to be able to read, from the MainView, the current (or last) value of the UISlider and textbox.

Keep in mind I am new to development on a Mac, and would appreciate any guidance as to where I should look up such information, be it through the use of delegates or perhaps I am missing something obvious in the structure of the template.

UPDATE: I am taking a look at the structure and have some more details: The UISlider is being created in FlipsideView.m. I noticed that the Done button is created from RootViewController.m and probably I should move the UISlider code over there. I may incorrectly be using the View to keep code that would be more appropiate in a Controller.

回答1:

Ultimately you should be updating some underlying object with the values from the controller. In general, the slider belongs in the view layer - it's a display element. The action that adjusting the slider produces, however, is a component of the controller and it should fire back into your model to update a value. I highly recommend drawing boxes on a sheet of paper and trying to produce a clean a separation as possible for your application's layers - doing so in this case would produce two views for each "side" of the utility which would, via a controller, relate to a model. Then, the act of moving the slider would "instantly" update the model on the back. The Cocoa Fundamental video on the iPhone developer site demonstrates this to great effect.



回答2:

I'm in exactly the same situation: first iphone app, new to mac programming, creating a utility, sliders on the flipside.

By following the example and the free tutorial here (http://www.bestechvideos.com/2008/11/13/writing-iphone-app-free-episode) I determined that the sliders and other controls should be declared on the flipsideviewcontroller. (Which leave the view pretty empty - I guess the use of the Nib resource file for the UI leaves the ...View.m class pretty much redundant?)

Wisequark's answer is a bit to general to help me though. In terms of specifics: - I can't find that video is there a link? - Could we see some code showing the Controller-Model code? - How do I persist the values set on the slider without having to build UI to go in the system settings?

(BTW is an Answer the right place to add to the question?)