2014년 11월 9일 일요일

아이폰 - 수업시간에 사용했던 피커뷰 데모 코드 입니다.

수업시간에 사용했던 피커뷰 데모 코드 입니다.
 조회 : 340
나의 폴더 > 아이폰 | 2011-06-09 (Thu) 11:45http://blog.dreamwiz.com/papasmf1/13667684
아이폰에서 많이 사용하는 피커뷰 데모 코드입니다.
아무래도 UI쪽에서 보는게 이해하는데 빠른 것 같습니다.

//피커뷰를 사용한 데모(14)

#import <UIKit/UIKit.h>

//2개의 프롵콜을 채택한다아래와 같이 추가한다.
@interface demo4_PickerViewController : UIViewController
<UIPickerViewDataSourceUIPickerViewDelegate>
{
//Picker View컨트롤에 추가할 배열을 선언한다.
NSArray *activities;
NSArray *feelings;
//Picker View컨트롤에 연결
IBOutlet UIPickerView *tweetPicker;
//UILabel과 연결
IBOutlet UILabel *display;
}

//Property를 추가한다.
@property (nonatomicretainUIPickerView *tweetPicker;
@property (nonatomicretainUILabel *display;

//버튼 클릭을 처리할 부분
- (IBAction) sendButtonTapped: (id) sender;
@end


//
// demo4_PickerViewController.m
// demo4_Picker
//
// Created by 김종덕 on 11. 5. 25..
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "demo4_PickerViewController.h"

@implementation demo4_PickerViewController

//게터세터를 만들어라
@synthesize tweetPicker;
@synthesize display;

//버튼을 클릭했을 때 코드
- (IBAction) sendButtonTapped:(id)sender
{
NSString *theMessage = [NSString stringWithFormat:@"현재 작업:%@ 느낌:%@",
[activities objectAtIndex:[tweetPicker selectedRowInComponent:0]],
[feelings objectAtIndex:[tweetPicker selectedRowInComponent:1]]];
//NSLog(theMessage);
[display setText:theMessage];
}

//사용한 객체 참조를 해지한다.
- (void)dealloc
{
[activities release];
[feelings release];
[tweetPicker release];
[super dealloc];
}

- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
}

//프로토콜의 두개의 필수 메서드를 구현한다.
- (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
//컴포넌트는 몇개가 있는가?
return 2;
}

- (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
//각 배열의 행의 숫자가 다르므로 따로 리턴한다.
if (component == 0)
return [activities count];
else
return [feelings count];
}

//피커뷰를 선택했을 때 값을 넘겨주는 메서드도 구현한다.
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
switch (component) {
case 0:
return [activities objectAtIndex:row];

case 1:
return [feelings objectAtIndex:row];

}

return nil;
}

인터페이스 빌더와 코드를 연결할 때 다음과 같이 실행합니다.
//닙에 연결할 때 피커뷰를 먼저 선택하고 마우스 오른쪽 버튼을 클릭하고
//그중에 데이터소스를 File's OWner로 드래그 한다.
//다시 피커뷰를 선택하고 델리게이트를 File's Owner로 드래그 한다.
//버튼을 컨트롤 키를 누른 상태에서 File'sOwner로 드래그 한다.
//File's Owner에서 라벨로 드래그 한다.
//마지막으로 File's Owner에서 tweetPicker로 드래그해서 IBOutlet을 연결한다.

#pragma mark - View lifecycle


//주석을 제거하고 배열을 초기화 한다.
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
activities = [[NSArray allocinitWithObjects:@"잠자기"@"먹기"@"놀기",
@"코딩"@"수업"@"연습"@"쇼핑"@"게임"nil];
feelings = [[NSArray allocinitWithObjects:@"놀랍다"@"슬프다"@"행복하다",
@"별로다"@"그냥그렇다"@"화가난다"nil];

[super viewDidLoad];
}


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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

댓글 없음:

댓글 쓰기

참고: 블로그의 회원만 댓글을 작성할 수 있습니다.

5월 14일 새벽에 chatGPT 4o가 발표되었습니다. 옵티마이즈, 옴니라는 의미인데 실시간 통역, 다자간 회의, 멀티모달 기능의 강화등이 보이네요.

  초격차로 OpenAI진영이 다시 앞서가는 모양을 보여주고 있습니다. 저도 새벽에 일어나자 마자 올라온 영상들과 글을 정리하고 있습니다. ㅎㅎ 영화 HER의 사진이 새벽에 많이 올라왔었는데 저도 안본 영화입니다. 주말에 한번 봐야 할 것 같습니다....