교육의 막바지까지 왔구나!!..
여러가지 자바와 다른 개념들이 있고 공통적으로 쓰이는 개념도 많다.
특히 메모리 관리나 API들이 광건 인 것 같다.
@@@@촛불켜기@@@@@
AppDelegate.h
//
// AppDelegate.h
// LightTheCandle
//
// Created by SDS107 on 12. 3. 30..
// Copyright (c) 2012년 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UIImageView *candleImageView;
UISwitch *onOffSwitch;
UILabel *candleStateLabel;
BOOL candleState;
UIImage *candleOffImage;
UIImage *candleOnImage;
}
// 그림으로 그린 객체와 코드를 연결
@property (strong, nonatomic) IBOutlet UIWindow *window;
@property (strong, nonatomic) IBOutlet UIImageView *candleImageView;
@property (strong, nonatomic) IBOutlet UISwitch *onOffSwitch;
@property (strong, nonatomic) IBOutlet UILabel *candleStateLabel;
-(IBAction)toggleCandle:(id)sender;
@end
AppDelegate.m
//
// AppDelegate.m
// LightTheCandle
//
// Created by SDS107 on 12. 3. 30..
// Copyright (c) 2012년 __MyCompanyName__. All rights reserved.
//
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize onOffSwitch, candleImageView, candleStateLabel; // add
@synthesize window = _window;
- (void)dealloc
{
[_window release];
[candleOffImage release]; // add
[candleOnImage release]; // add
[super dealloc];
}
// add
-(IBAction)toggleCandle:(id)sender
{
candleState = !candleState;
if(candleState){
//on
[candleImageView setImage:candleOnImage];
onOffSwitch.on = YES;
candleStateLabel.text = @"촛불이 켜졌습니다.";
}else{
// off
[candleImageView setImage:candleOffImage];
onOffSwitch.on= NO;
candleStateLabel.text = @"촛불이 꺼졌습니다.";
}
}
// 초기화 작업을 많이 함. didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
candleState = NO;
NSString *candleOnPath = [[NSBundle mainBundle]
pathForResource:@"candle on" ofType:@"jpg"];
// NSBundle mainBundle 리소스가 배포되어있는 공간
//
NSString *candleOffPath = [[NSBundle mainBundle]
pathForResource:@"candle off" ofType:@"jpg"];
candleOffImage = [[UIImage alloc] initWithContentsOfFile:candleOffPath];
candleOnImage = [[UIImage alloc] initWithContentsOfFile:candleOnPath];
[candleImageView setImage:candleOffImage];
onOffSwitch.on = candleState;
candleStateLabel.text = @"촛불이 꺼져있습니다.";
// 주석 self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
// 주석 self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
'Language > iPhone' 카테고리의 다른 글
5일차 : Objective C 오후 (0) | 2012.03.30 |
---|---|
제4장. Objective c 하편 (0) | 2012.03.29 |
제 4장. Objective C (6) | 2012.03.29 |
제3장. Objective C[오전+오후] (0) | 2012.03.28 |
제2장. Objective C (하편) (0) | 2012.03.27 |