3단 헤테로 피커뷰 소스코드


// h  --------------------------------------

#import! <UIKit/UIKit.h>

#define groupComponent 0
#define memberComponent 1
#define countComponent 2 //

@interface pick3ViewController : UIViewController 
<UIPickerViewDelegate, UIPickerViewDataSource> 
{
UIPickerView *giveMePicker;    
    NSDictionary *giveMeList;
    
    NSArray *groupName;    
    NSArray *memberName;
NSArray *countType; //
}
@property (nonatomicretainIBOutlet UIPickerView *giveMePicker;
@property (nonatomicretain) NSDictionary *giveMeList;
@property (nonatomicretain) NSArray *groupName;
@property (nonatomicretain) NSArray *memberName;
@property (nonatomicretain) NSArray *countType; //

- (IBAction)buttonPressed:(id)sender;

@end

// m ----------------------------------

#import! "pick3ViewController.h"

@implementation pick3ViewController

@synthesize giveMePicker, giveMeList, groupName, memberName, countType;

#pragma mark -
#pragma mark 화면 이벤트 처리
//!!!: 결과버튼 클릭시피커의 선택된 항목 경고창에 표시
- (IBAction)buttonPressed:(id)sender {
    
    //NSInteger groupRow = [giveMePicker selectedRowInComponent:groupComponent];    
    NSInteger memberRow = [giveMePicker selectedRowInComponent:memberComponent];
    NSInteger countRow = [giveMePicker selectedRowInComponent:countComponent]; //
    //NSString *group = [self.groupName objectAtIndex:groupRow];
    NSString *member = [self.memberName objectAtIndex:memberRow];
    NSString *count = [self.countType objectAtIndex:countRow]; //
// 알림창용 제목
    NSString *title = [[NSString allocinitWithFormat:@"여기요"];    
// 알림창용 내용
    NSString *message = [[NSString allocinitWithFormat:@"%@ %@ 주세요!", member, count];
    
// 알림창
    UIAlert!View *alert! = [[UIAlert!View allocinitWithTitle:title message:message 
 delegate:nil cancelButtonTitle:@"확인" otherButtonTitles:nil];    
    [alert! show];
    
    [alert! release];
    [title release];
    [message release];
    
}

#pragma mark -
#pragma mark 초기화
//!!!:  기동후초기화
- (void)viewDidLoad {
    
NSArray *countArray =[[NSArray allocinitWithObjects:@"1",@"2"@"3"
  @"4",@"5"nil];
self.countType = countArray;
[countArray release];
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *plistPath = [bundle pathForResource:@"GiveMe" ofType:@"plist"];
    NSDictionary *dictionary = [[NSDictionary allocinitWithContentsOfFile:plistPath];
    self.giveMeList = dictionary;
    
    [dictionary release];
    
    NSArray *components = [self.giveMeList allKeys];
    NSArray *sorted = [components sortedArrayUsingSelector:@selector(compare:)];
    
    self.groupName = sorted;
    
    NSString *selectedGroup = [self.groupName objectAtIndex:0];
    NSArray *array = [giveMeList objectForKey:selectedGroup];
    
    self.memberName = array;
    
    [super viewDidLoad];
}

#pragma mark -
#pragma mark 피커뷰 메써드 오버라이드

//!!!: 전체   리턴
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 3;
}
//!!!:  단별 항목  리턴
- (NSInteger)pickerView:(UIPickerView *)pickerView 
numberOfRowsInComponent:(NSInteger)component {
    
    if (component == groupComponent) {
        return [groupName count];        
    } else if (component == memberComponent){
        return [memberName count];        
    }else {
return [countType count];  
}
}
//!!!:  항목별 항목명
- (NSString *)pickerView:(UIPickerView *)pickerView 
             titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    
    if (component == groupComponent) {
        return [groupName objectAtIndex:row];
    } else if (component == memberComponent){
        return [memberName objectAtIndex:row];
    }else {
return [self.countType objectAtIndex:row];
}
}
//!!!: 1 선택시 2 애니메이션
- (void)pickerView:(UIPickerView *)pickerView 
      didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    
    if (component == groupComponent) {
        
        NSString *selectedGroup = [self.groupName objectAtIndex:row];
        NSArray *array = [giveMeList objectForKey:selectedGroup];
        
        self.memberName = array;
        
        [giveMePicker selectRow:0 inComponent:memberComponent animated:YES];
        [giveMePicker reloadComponent:memberComponent];
    }
}

#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)viewDidUnload {
    self.giveMePicker = nil;
    self.giveMeList = nil;
    self.groupName = nil;
    self.memberName = nil;
self.countType = nil;
}

- (void)dealloc {
    [giveMePicker release];
    [giveMeList release];
    [groupName release];
[countType release];
    
    [memberName release];
    
    [super dealloc];
}

@end

댓글

이 블로그의 인기 게시물

Draw Circle on PictureBox when Button Click - Winform

2D FFT of Gray Image by AForge