MoviePlayer has 4 classes:
MoviePlayerAppDelegateMyImageViewMyOverlayViewMyViewController
MPC, MPCAppDelegate and MPCViewController. Therefore, MyImageView and MyOverlayView are additions while MyViewController has been renamed.MoviePlayerAppDelegate
Interface
There are 2 different ways of including a file/class:#import "MyViewController.h"@class MyViewController;
NSInteger aside from the default UIWindow and ViewController:backgroundColorcontrolModescalingMode
@property declares the accessor methods for the 5 variables. It has attributes which modify the accessors.Example:
@property (nonatomic, retain) UIWindow *window;nonatomic means the accessor returns the value directly, the default is to lock, get value, unlock which is meant for multithreaded environments.assign, retain or copy must be explicitly set if garbage collection is not used. assign is the default and means the setter uses a simple assignment. retain keeps the object variable in-memory and cannot be deallocated without your permission. copy means that a copy of the object should be used for assignment and the previous one is sent a release message.3 instance methods:
-(void)setUserSettingsDefaults;-(void)applicationDidFinishLaunching:(UIApplication *)application;-(void)dealloc;
Implementation
3 NSString keys:kScalingModeKey = @"scalingMode"kControlModeKey = @"controlMode"kBackgroundColorKey = @"backgroundColor"
@synthesize generates the accessors according to the attributes listed. If implemented manually, the code must follow what has been specified in the @property. @synthesize will only generate accessors that don't exist so if a variable has a setter already, then only a getter will be generated.-(void)setUserSettingsDefaultsSets up a test calling
NSUserDefaults to see if there's a match. Passing will set the scalingMode, controlMode and backgroundColor variables. Failing will create the values based on the settings bundle info and then set the variables:- Get the path to the main bundle of the project.
- Append
Settings.bundleto the path usingstringByAppendingPathComponent, which takes care of adding separators. - Append
Root.plistto the path, same as before. - Create a dictionary using
dictionaryWithContentsOfFile, giving the path toRoot.plist. - Create the
prefSpecifierArrayarray from the dictionary using the key,PreferenceSpecifiers, which is a tag inRoot.plist.Root.plistis an XML file with dict, array and key tags. May be an easy way to read XML.
- Declare 3
NSNumbervariables and a dictionary,prefItem. - Loop
prefSpecifierArraywith the current value going intoprefItem. - Set
keyValueStrwith the dictionary using the key,'Key'. - Set
defaultValuewith the dictionary using the key,'DefaultValue'. - Check if
keyValueStris equal to anyNSStringsspecified above. - Set the numbers with
defaultValueif any is correct. - Create a dictionary containing the default values and their keys.
- Register the dictionary with
NSUserDefaultsusingregisterDefaults. - Updates and writes to the persistent domains using
synchronize.
-(void)applicationDidFinishLaunching:(UIApplication *)applicationAdd the
ViewController's view as a subview of the UIWindow. Call self with setUserSettingsDefaults to get the default movie player settings. Lastly, call the ViewController with initMoviePlayer to create a movie player object.-(void)deallocRelease the
UIWindow and the ViewController. Call the super's dealloc method.
No comments:
Post a Comment