2011년 5월 19일 목요일

iphone 네비게이션바 제어하기

//
//  SampleDay4_2AppDelegate.m
//  SampleDay4-2
//
//  Created by bit on 11. 5. 19..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SampleDay4_2AppDelegate.h"

@implementation SampleDay4_2AppDelegate

@synthesize window;
@synthesize mNavi;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    // Override point for customization after application launch.

    self.window.rootViewController = self.mNavi;
//[self.mNavi setNavigationBarHidden:YES]; 
    [self.window makeKeyAndVisible];
    
    return YES;
}




//
//  FirstView.m
//  SampleDay4-2
//
//  Created by bit on 11. 5. 19..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "FirstView.h"
#import "SecondView.h"


@implementation FirstView

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
self.title = @"First";
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

-(IBAction)onClickNext:(id)sender
{
SecondView *view = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
[self.navigationController pushViewController:view animated:YES];
[view release];
}


@end



//
//  SecondView.m
//  SampleDay4-2
//
//  Created by bit on 11. 5. 19..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//



-(IBAction)onClickBack:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}

아이폰 tabview 넣기

//
//  SampleDay4_1AppDelegate.h
//  SampleDay4-1
//
//  Created by bit on 11. 5. 19..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import

@class SampleDay4_1ViewController;

@interface SampleDay4_1AppDelegate : NSObject {
    UIWindow *window;
UITabBarController *mTabbarController;
}


@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *mTabbarController;


@end




//
//  SampleDay4_1AppDelegate.m
//  SampleDay4-1
//
//  Created by bit on 11. 5. 19..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SampleDay4_1AppDelegate.h"
#import "SampleDay4_1ViewController.h"

@implementation SampleDay4_1AppDelegate

@synthesize window;
@synthesize mTabbarController;



#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    // Override point for customization after application launch.

    // Add the view controller's view to the window and display.
    //[self.window addSubview:viewController.view];
[self.window addSubview:mTabbarController.view];
    [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, called instead of applicationWillTerminate: when the user quits.
     */
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  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.
     See also applicationDidEnterBackground:.
     */
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}


- (void)dealloc {
[mTabbarController release];
    [window release];
    [super dealloc];
}


@end

아이폰 Controller

UINavigation Controller
• Navigation Conroller  - (id)initWithRootViewController:(UIViewController *)viewController;
• View controller  (Push) - (void)pushViewController:(UIViewController *)viewController
animated:(BOOL)animated;
View controller  (Pop) - (UIViewController *)popViewControllerAnimated:(BOOL)animated;
View Controller  (iPhone OS 3.0) - (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated;


UITabBarController
tabBarController = [[UITabBarController alloc] init];
View Controller  tabBarController.viewControllers = myViewControllers;
[window addSubview:tabBarController.view];
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@“Playlists”
image:[UIImage imageNamed:@“music.png”] tag:0]; self.tabBarItem = item;
[item release];



아이폰에서 새로운 뷰 생성하기

// create view

- (IBAction)onClickItem1:(id)sender
{
ViewItem1* fViewItem = [[ViewItem1 alloc] initWithNibName:@"ViewItem1" bundle:nil];
self.mViewItem1 = fViewItem;
[self.view addSubview:mViewItem1.view];
[fViewItem release];
}

// remove View

- (IBAction)onClickItem1Back:(id)sender
{
[self.view  removeFromSuperview];
}


2011년 5월 18일 수요일

이미지 슬라이드

/  SampleDay3_1ViewController.m
//  SampleDay3-1
//
//  Created by bit on 11. 5. 18..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SampleDay3_1ViewController.h"

@implementation SampleDay3_1ViewController
@synthesize imageView;
@synthesize timer;


/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
 [super loadView];
 //.. 
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
//UIImage *image = [UIImage imageNamed:@"Background_0.jpg"];
// [self.imageView setImage:image];
//
idx = 0;
[self loadImageByIndex:idx];

}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}


- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.imageView = nil;
}


- (void)dealloc {
    [super dealloc];
}

- (IBAction)onPrevious:(id)sender
{
if ( --idx < 0 ) {
idx = 5;
}
[self loadImageByIndex:idx];
}
- (IBAction)onNext:(id)sender
{
if (++idx > 5 ) {
idx = 0;
}
[self loadImageByIndex:idx];
}
- (IBAction)onSwitchChanged:(id)sender
{
UISwitch *sw = (UISwitch *)sender;
NSLog(@"onSwitchChanged");
if ( sw.on == YES) {
// NSTimer *_timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(onTimerCallback:) userInfo:nil repeats:YES ];
NSTimer *_timer1 = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(onTimerCallback:) userInfo:nil repeats:YES]; 
   
NSLog(@"sw.on YES");
self.timer = _timer1;
}
else {
NSLog(@"sw.on NO");
}
}


- (void)onTimerCallback:(NSTimer *)_timer
{
[self onNext:nil];
NSLog(@"Timer");
}

- (void)loadImageByIndex:(NSInteger)index
{
NSString *imageName = [NSString stringWithFormat:@"Background_%d.jpg", index];
UIImage *image = [UIImage imageNamed:imageName];
[self.imageView setImage:image];
}


@end

아이폰에서 텍스트 박스에서 키보드 없애기

다른 영역을 누를때 키보드를 없애려면 보이지 않는 버튼을 만들어서 해당 버튼이 눌러지면 
키보드를 없애 준다. 


- (IBAction)OnTextFieldEditingDone:(id)sender   // 완료 버튼 눌렀을때 작업 
{
[textField resignFirstResponder]; //  해당 코드로 이벤트를 포기한다. 
UIAlertView *alertView = [[ UIAlertView alloc
  initWithTitle:@"title" 
  message: textField.text
  delegate: nil 
  cancelButtonTitle:@"Cancel" 
  otherButtonTitles:@"OK", nil ];
[alertView show];
[alertView release];
}

- (IBAction)OnClickBGButton:(id)sender   // 가상의 버튼을 눌렀을때 작업 
{
[textField resignFirstResponder];
}