Your SlideShare is downloading. ×
아이폰프로그래밍(2)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

아이폰프로그래밍(2)

737
views

Published on


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
737
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. (2) Bit Academy
  • 2. • MVC • • • • NSDictionary
  • 3. MVC • Model View Controller : , , . • Model : • View : • Controller :
  • 4. MVC LightTheCandle • LightTheCandleAppDelegate • MVC Candle class Controller
  • 5. NSDictionary
  • 6. Candle
  • 7. Candle • LightTheCandleAppDelegate candleState, candleOffImage, candleOnImage Candle . • LightTheCandleAppDelegate Candle .
  • 8. • candle candleState . • candleState getter • candleState setter set + CandleState = setCandleState.
  • 9. Candle.h #import <Foundation/Foundation.h> @interface Candle : NSObject { ! BOOL candleState; ! UIImage *candleOnImage; ! UIImage *candleOffImage; } - (BOOL)candleState; - (void)setCandleState:(BOOL)newState; - (UIImage *)candleOnImage; - (void)setCandleOnImage:(UIImage *)newImage; - (UIImage *)candleOffImage; - (void)setCandleOffImage:(UIImage *)newImage; /* @property (assign) BOOL candleState; @property (retain) UIImage *candleOnImage; @property (retain) UIImage *candleOffImage; */ @end
  • 10. • LightTheCandleAppDelegate applicationDidFinishLaunching: Candle . • -(id)init . NSObject
  • 11. Candle.m init init ! self super init ; ! self ! ! candleState ; ! ! candleOnPath mainBundle pathForResource ofType ; ! ! candleOffPath mainBundle pathForResource ofType ; ! ! candleOffImage UIImage alloc initWithContentsOfFile candleOffPath ; ! ! candleOnImage UIImage alloc initWithContentsOfFile candleOnPath ; !   ! self;
  • 12. Candle candleState ! candleState; Candle.m setCandleState newState ! candleState newState;   UIImage candleOffImage ! candleOffImage; setCandleOffImage UIImage newImage ! UIImage oldImage candleOffImage; ! oldImage newImage ! ! candleOffImage newImage retain ; ! ! oldImage oldImage release ; !   UIImage candleOnImage ! candleOnImage; setCandleOnImage UIImage newImage ! UIImage oldImage candleOnImage; ! oldImage newImage ! ! candleOnImage newImage retain ; ! ! oldImage oldImage release ; !
  • 13. LightTheCandleAppDelegate • Candle • Candle *myCandle .h • myCandle = [[Candle alloc] init] .m • @class Candle .m #import “Candle.h”
  • 14. applicationDidFinishLaunching applicationDidFinishLaunching UIApplication application   ! myCandle Candle alloc init ; !   ! candleImageView setImage myCandle candleOffImage ; onOffSwitch.on = [myCandle candleState]; candleStateLabel.text = @”Candle is Off. Please light on”; window makeKeyAndVisible ;
  • 15. togggleCandle IBAction toggleCandle sender ! myCandle setCandleState myCandle candleState ; ! myCandle candleState ! ! ! ! candleImageView setImage myCandle candleOnImage ; ! ! onOffSwitch.on ; ! ! candleStateLabel.text ; ! ! ! ! ! candleImageView setImage myCandle candleOffImage ; ! ! onOffSwitch.on ; ! ! candleStateLabel.text ; !
  • 16. • . • • Property synthesize
  • 17. property Candle Candle Candle ! candleState; ! candleState; ! UIImage candleOffImage; ! UIImage candleOffImage; ! UIImage candleOnImage; ! UIImage candleOnImage;     candleState; assign candleState; setCandleState newState; retain UIImage candleOffImage;   retain UIImage candleOnImage; UIImage candleOffImage;   setCandleOffImage UIImage newImage;     UIImage candleOnImage; setCandleOnImage UIImage newImage;   Candle   candleState ! candleState; setCandleState newState ! candleState newState; UIImage candleOffImage ! candleOffImage; setCandleOffImage UIImage newImage Candle ! UIImage oldImage candleOffImage; ! oldImage newImage   ! ! candleOffImage newImage retain ; candleState; ! ! oldImage oldImage release ; candleOffImage; ! candleOnImage; UIImage candleOnImage ! candleOnImage; setCandleOnImage UIImage newImage ! UIImage oldImage candleOnImage; ! oldImage newImage ! ! candleOnImage newImage retain ; ! ! oldImage oldImage release ; !
  • 18. NSDictionary • Candle *myCandle -> .h file NSMutableDictionary *myCandleDict • myCandle = [[Candle alloc] init] -> myCandleDict = [[NSMutableDictionary alloc] initWithCapacity:10] appDelegate.m file
  • 19. -applicationDidFinishLaunching candleState = NO; NSString *candleOnPath = [[NSBundle mainBundle] pathForResource: @”candle on” ofType: @”jpg”]; NSString *candleOffPath = [[NSBundle mainBundle] pathForResource: @”candle off” ofType: @”jpg”]; candleOffImage = [[UIImage alloc] initWithContentsOfFile:candleOffPath]; candleOnImage = [[UIImage alloc] initWithContentsOfFile:candleOnPath]; [myCandleDict setValue: [NSNumber numberWithBool: candleState] forKey:@”candleState”]; [myCandleDict setValue: candleOffImage forKey:@”candleOffImage”]; [myCandleDict setValue:candleOnImage forKey:@”candleOnImage”]; Integer, Float, Bool NSNumber
  • 20. toggleCandle -(IBAction)toggleCandle:(id)sender { BOOL candleState = [[myCandleDict valueForKey: @”candleState”] boolValue]; [myCandleDict setValue:[NSNumber numberWithBool:!candleState] forKey:@”candleState”]; if(!candleState) { //On [candleImageView setImage:[myCandleDict valueForKey:@”candleImage”]]; onOffSwitch.on = YES; candleStateLabel.text = @”Candle is now on”; } else { //Off [candleImageView setImage: [myCandleDict valueForKey: @”candleOffImage”]]; onOffSwitch.on = NO; candleStateLabel.text = @”Candle is off. please light on”; } }

×