Migrating a simple application from Application Delegate to ViewController Class
Frst of all wanted to send out a huge thanks for the great feedback and support.
I have a simple application working, right now simply loads a sequence of images and alows the user to step thru the images by clicking a button. All of my logic is in my Application Delegate class, with the image loading, initialization of UIImage Views etc happening in my applicationDidFinishLaunching method. My next step is to migrate as much as possible all of the logic from this class to a ViewController, to take advantage of the extra functionality etc in viewcontrollers.All my images and imageViews are initialized like the following in my applicationDidFinishLaunching.
开发者_高级运维 img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@image1.jpg" ofType:nil]];
imgView = [[UIImageView alloc] initWithImage:img];
How would I migrate this to a ViewController based application?
Can I assume that all of the logic currently in my applicationDidFinishLaunching method can be put in the viewDidLoad method of my viewController?Assuming you used one of the standard iPhone templates, you should already have a subclassed ViewController in your app. All of the code you'd like to move from the app delegate should be moved into that View Controller, starting with the viewDidLoad
method.
Timely advice, since I just did this exact same thing a few months ago (as a learning exercise), move slowly. Move the smallest possible chunks of code you can, then compile and run after each step. Better yet, set up unit tests before you start copying working code around.
精彩评论