카테고리 선택뷰 + 2단 피커뷰 랜덤 섞기 소스
// MainViewController.h
// IdeaSon
//
// Created by SimpleVisual on 11. 10. 5..
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#define kTech1Compo 0 // 회전판 타입지정
#define kTech2Compo 1
#import "FlipsideViewController.h"
@interface MainViewController : UIViewController
<FlipsideViewControllerDelegate, UIPickerViewDelegate, UIPickerViewDataSource>
{
IBOutlet UIPickerView *picker1;
NSArray *pick1Type;
NSArray *pick2Type;
}
@property(nonatomic, retain)UIPickerView *picker1;
@property(nonatomic, retain)NSArray *pick1Type;
@property(nonatomic, retain)NSArray *pick2Type;
- (IBAction)showInfo:(id)sender;
- (IBAction)buttonPress; // Other Mix
@end
-------------------------
// MainViewController.m
// IdeaSon
//
// Created by SimpleVisual on 11. 10. 5..
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "MainViewController.h"
#import "IdeaSonAppDelegate.h" // 변수 공유용
@implementation MainViewController
@synthesize picker1;
@synthesize pick1Type;
@synthesize pick2Type;
#pragma mark -
#pragma mark 버튼 이벤트 핸들링
//!!!: Other Idea
-(IBAction)buttonPress {
IdeaSonAppDelegate *del1 =
(IdeaSonAppDelegate *)[[UIApplication sharedApplication] delegate];
del1.categ1 = (int)[picker1 selectedRowInComponent:0];
del1.categ2 = (int)[picker1 selectedRowInComponent:1];
FlipsideViewController *controller = [[FlipsideViewController alloc]
initWithNibName:@"FlipsideView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
//!!!: 플립뷰로 넘어가기
- (IBAction)showInfo:(id)sender {
FlipsideViewController *controller = [[FlipsideViewController alloc]
initWithNibName:@"FlipsideView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
#pragma mark -
#pragma mark 초기화
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *categoryArr=[[NSArray alloc] initWithObjects:
@"앱개발", @"IT융합", @"LMS", @"수학", @"응용분야", nil];
self.pick1Type=categoryArr;
self.pick2Type=categoryArr;
[categoryArr release];
}
#pragma mark -
#pragma mark pickerDataSource 메쏘드
//!!!: 갯수
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 2; // 2개 회전판
}
///!!!: 항목 크기 갯수
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component {
if(component == kTech1Compo) {
return [self.pick1Type count];
}
else
return [self.pick2Type count];
}
//!!!: 하나 하나 항목 대입
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
if(component == kTech1Compo) {
return [self.pick1Type objectAtIndex:row];
}
else
return [self.pick2Type objectAtIndex:row];
}
#pragma mark -
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
[self dismissModalViewControllerAnimated:YES];
}
- (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)dealloc {
[pick1Type release];
[pick2Type release];
[super dealloc];
}
@end
------------------------
// FlipsideViewController.h
// IdeaSon
//
// Created by SimpleVisual on 11. 10. 5..
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#define kTech1Compo 0 // 회전판 타입지정
#define kTech2Compo 1
#import <UIKit/UIKit.h>
@protocol FlipsideViewControllerDelegate;
@interface FlipsideViewController : UIViewController
<UIPickerViewDelegate, UIPickerViewDataSource>{
id <FlipsideViewControllerDelegate> delegate;
IBOutlet UIPickerView *picker1;
NSArray *pick1Type;
NSArray *pick2Type;
IBOutlet UILabel *label1;
IBOutlet UILabel *label2;
}
@property(nonatomic, retain)UIPickerView *picker1;
@property(nonatomic, retain)NSArray *pick1Type;
@property(nonatomic, retain)NSArray *pick2Type;
@property(nonatomic, retain)UILabel *label1;
@property(nonatomic, retain)UILabel *label2;
@property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
- (IBAction)done:(id)sender;
- (IBAction)buttonPress; // Other Mix
@end
@protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
@end
----------------------------
// FlipsideViewController.m
// IdeaSon
//
// Created by SimpleVisual on 11. 10. 5..
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "FlipsideViewController.h"
#import "IdeaSonAppDelegate.h" // 변수 공유용
@implementation FlipsideViewController
@synthesize delegate;
@synthesize picker1;
@synthesize pick1Type;
@synthesize pick2Type;
@synthesize label1, label2;
#pragma mark -
#pragma mark 버튼 이벤트 핸들링
//!!!: Other Idea
-(IBAction)buttonPress {
int randNum1=rand() % [self.pick1Type count];
int randNum2=rand() % [self.pick2Type count];
[picker1 selectRow:randNum1 inComponent:0 animated:YES];
[picker1 selectRow:randNum2 inComponent:1 animated:YES];
}
#pragma mark -
#pragma mark 초기화
- (void)viewDidLoad {
[super viewDidLoad];
srand(time(NULL));
IdeaSonAppDelegate *del1 =
(IdeaSonAppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *appArr=[[NSArray alloc] initWithObjects:
@"마이크", @"스피커", @"근접센서", @"명암센서", @"가속도", @"위치센서",
@"터치", @"멀티터치", @"회전", @"확대축소", @"키패드", @"와이파이",
@"지도", @"테이블뷰", @"이미지뷰", @"웹뷰", @"컴파스", @"자이로",
@"카메라", @"동영상", @"DB", @"백그라운드", @"메일", @"문자", @"그림",
@"APNS", @"트위터", @"아이튠즈", @"클라우드", @"게임", @"날씨",
@"생산성", @"뉴스", @"RSS", @"달력", @"팟캐스트", @"파일재생", @"영상처리",
@"수면", @"증강현실", @"QRCode", @"인터넷", @"지역화", @"슬라이드", nil];
NSArray *itArr=[[NSArray alloc] initWithObjects:
@"USN", @"노트북", @"아이패드", @"WiFi", @"블루투스", @"VLC", @"그리드",
@"웹서버", @"리눅스", @"암호", @"RFID", @"화상회의", @"생체인식", @"VRML",
@"DB", @"전자결재", @"가상현실", @"가상화", @"병렬처리", @"대역폭", @"실시간",
@"와이브로", @"오피스", @"LBS", @"GIS", @"인공지능", nil];
NSArray *lmsArr=[[NSArray alloc] initWithObjects:
@"기존조명", @"LED조명", @"상황인지", @"센서", @"인공지능", @"제어기",
@"조도센서", @"재실센서", @"색온도", @"온도센서", @"습도센서", @"방범센서",
@"태양광", @"파사드", @"전력절감", @"유지보수", @"가시광통신", @"선박",
@"열차", @"주차장", @"스토어", @"아파트", @"공장", @"빌딩", @"EMS",
@"RF", @"DMX", @"DALI", nil];
NSArray *mathArr=[[NSArray alloc] initWithObjects:
@"수치해석", @"고등통계", @"선형대수", @"해석학", @"신호처리", @"푸우리에",
@"인공신경망", @"웨이블렛", @"영상처리", @"패턴인식", @"비모수처리",
@"시계열분석", @"퍼지추론", @"칼만필터", @"SVM", @"전문가시스템",
@"프로파일", @"프랙탈", @"벡터", @"무한대", @"수열", nil];
NSArray *areaArr=[[NSArray alloc] initWithObjects:
@"로봇", @"주택", @"의류", @"농업", @"수산업", @"통신", @"의료", @"교육",
@"육아", @"실버", @"물류", @"건설", @"화학", @"철강", @"정부", @"국방",
@"금융", @"가전", @"원자력", @"홈네트웍", @"우주", @"정치", @"치안", nil];
if (del1.categ1 == 0) {
self.pick1Type=appArr;
[label1 setText:@"앱개발"];
}else if (del1.categ1 == 1){
self.pick1Type=itArr;
[label1 setText:@"IT기술"];
}else if (del1.categ1 == 2){
self.pick1Type=lmsArr;
[label1 setText:@"LMS기술"];
}else if (del1.categ1 == 3){
self.pick1Type=mathArr;
[label1 setText:@"수학"];
}else {
self.pick1Type=areaArr;
[label1 setText:@"응용분야"];
}
if (del1.categ2 == 0) {
self.pick2Type=appArr;
[label2 setText:@"앱개발"];
}else if (del1.categ2 == 1){
self.pick2Type=itArr;
[label2 setText:@"IT기술"];
}else if (del1.categ2 == 2){
self.pick2Type=lmsArr;
[label2 setText:@"LMS기술"];
}else if (del1.categ2 == 3){
self.pick2Type=mathArr;
[label2 setText:@"수학"];
}else {
self.pick2Type=areaArr;
[label2 setText:@"응용분야"];
}
[appArr release];
[itArr release];
[lmsArr release];
[mathArr release];
[areaArr release];
}
#pragma mark -
#pragma mark pickerDataSource 메쏘드
//!!!: 갯수
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 2; // 3개 회전판
}
///!!!: 항목 크기 갯수
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component {
if(component == kTech1Compo) {
return [self.pick1Type count];
}
else
return [self.pick2Type count];
}
//!!!: 하나 하나 항목 대입
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
if(component == kTech1Compo) {
return [self.pick1Type objectAtIndex:row];
}
else
return [self.pick2Type objectAtIndex:row];
}
- (IBAction)done:(id)sender {
[self.delegate flipsideViewControllerDidFinish:self];
}
#pragma mark -
#pragma mark 안전해제
- (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)dealloc {
[label1 release];
[label2 release];
[pick1Type release];
[pick2Type release];
[super dealloc];
}
@end
댓글
댓글 쓰기