2013-01-09 52 views
-1

我有一个pickerView有两个组件,它们是“天”和“月”,我需要根据选定的月份重新加载日期,例如:picker视图开始1月1日,1月有31天,所以我需要第一个组件有31个对象,日子...但是,然后,用户将月份更改为4月,然后,我需要将第一个组件更改为30个对象...根据其他组件重新加载pickerView的组件

我的代码是这样的:

- (void)viewDidLoad { 

    [super viewDidLoad]; 

    list31 = [[NSMutableArray alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12", @"13", @"14", @"15", @"16", @"17", @"18", @"19", @"20", @"21", @"22", @"23", @"24", @"25", @"26", @"27", @"28", @"29", @"30", @"31",nil]; 

    list30 = [[NSMutableArray alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12", @"13", @"14", @"15", @"16", @"17", @"18", @"19", @"20", @"21", @"22", @"23", @"24", @"25", @"26", @"27", @"28", @"29", @"30",nil]; 

    list29 = [[NSMutableArray alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12", @"13", @"14", @"15", @"16", @"17", @"18", @"19", @"20", @"21", @"22", @"23", @"24", @"25", @"26", @"27", @"28", @"29",nil]; 

    listMonth = [[NSMutableArray alloc] initWithObjects:@"Janeiro", @"Fevereiro", @"Março", @"Abril", @"Maio", @"Junho", @"Julho", @"Agosto", @"Setembro", @"Outubro", @"Novembro", @"Dezembro", nil]; 

} 


- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

-(NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView{ 

    return 2; 

} 

-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ 

    if(component == 0){ 
     if() { 
      return [list31 count]; 
     } else if() { 
      return [list30 count]; 
     } else if() { 
      return [list29 count]; 
     } 
    } else if(component == 1) { 
     return [listMonth count]; 
    } 
} 

-(NSString *) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ 

    if(component == 0){ 
     if() { 
      return [list31 objectAtIndex:row]; 
     } else if() { 
      return [list30 objectAtIndex:row]; 
     } else if() { 
      return [list29 objectAtIndex:row]; 
     } 
    } else if(component == 1) { 
     return [listMonth objectAtIndex:row]; 
    } 
} 

-(void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ 

    if(component == 0){ 
     //dont know yet 
    } 
    if(component == 1){ 
     NSString *mes = [[NSString alloc] initWithFormat:@"%@", [listMonth objectAtIndex:row]]; 
     month.text = mes; 
    } 

} 

我有,如果已经准备,但我不知道该怎么放进表达面积......而在“didSelect行“我不知道我会放在那里的代码。我GOOGLE了很多,但还没有找到任何东西...

*对不起我的代码的某些部分是在葡萄牙,但他们只是变量名...

+0

您可以使用UIPickerView来执行此操作,但最好使用UIDatePicker。 –

+0

@JackHumphries UIDatePicker有几年,我只想要几天和几个月 –

+0

从这里检查我的答案http://stackoverflow.com/questions/13493402/show-data-in-uipickerview-second-component-based-on-first-元件选择 – TonyMkenu

回答

0

词根记忆插座你的选择器视图。
2.使用说出来让我们重新加载所有组件 - pickerView:didSelectRow:inComponent:
3.使用开关或标志来改变任何组件的,有数据源,所有的代表将被调用一次使用reloadAllcomponents

相关问题