ios에서 사용자 정의 UIPickerView 데이터 배치

1. 2개의 선택기가 있는 UIPickerView를 사용자정의합니다.
2. 관련된 코드는
      :

#define YearPicker 0
#define MonthPicker 1
@property(nonatomic,retain) NSMutableArray * years;
@property(nonatomic,retain) NSMutableArray * months;


m        


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [Tools setView:self.view backgourndImg:@"background.png"];
        //        , 1990 2030
       //        ,12   
        years =  [[NSMutableArray  alloc] init];
        months = [[NSMutableArray  alloc] init];
        for( int i = 0 ; i< 40 ;i++)
        {
            [years  addObject:[[NSString alloc] initWithFormat:@"%d",i+1990]];
        }
        for( int i =0 ; i < 12 ; i++)
        {
            [months  addObject:[[NSString alloc] initWithFormat:@"%d",i+1]];
        }
    }
    return self;
}

//          ,        ,       ,   2
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}
//             
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (component == YearPicker) {
        return [self.years count];
    }
    return [self.months count];
}

-(void) viewDidAppear:(BOOL)animated
{
    // 2    ,           
    AppDelegate * delegate = [[UIApplication sharedApplication]delegate];
    [self.datePick selectRow:delegate.theSelectedYear -1990 inComponent:YearPicker animated:YES ];
    [self.datePick selectRow:delegate.theSelectedMonth-1 inComponent:MonthPicker animated:YES ];
    [super viewDidAppear:animated];
}

	

좋은 웹페이지 즐겨찾기