注意:我正确设置了委托,并且 UIPicker 在 ios6 中完美运行。在 ios5 中,仅当我选择 row0 或 row5 时才调用 didSelectRow: 回调。我有 12 行。
有谁知道可能出了什么问题?
注意:UIPicker 的委托和数据源指向具有以下代码的类。
// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
if ([pickerView isKindOfClass:[MIDatePicker class]]) {
switch (self.pickermode) {
case MIDatePickerModeDayMonth:
return 2;
break;
case MIDatePickerModeDayMonthYear:
return 3;
break;
default:
break;
}
}
return 3;
}
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
if ([pickerView isKindOfClass:[MIDatePicker class]]) {
//month , day , year
switch (component) {
case 0:{
return [self.monthsArray count];
}
break;
case 1:
{
return [self.daysArray count];
}
case 2:{
return [self.yearArray count];
}
default:
break;
}
}
return 3;
}
// returns width of column and height of row for each component.
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{
// month , day ,year
switch (component) {
case 0:{
return self.picker.frame.size.width/2;
}
case 1:
return self.picker.frame.size.width/6;
case 2:{
return self.picker.frame.size.width/3;
}
default:
break;
}
return self.picker.frame.size.width;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
return pickerView.frame.size.height/5;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
// month , day ,year
switch (component) {
case 0:{
return [NSString stringWithFormat:@" %@ ",[self.monthsArray objectAtIndex:row]];
}
case 1:
return [self.daysArray objectAtIndex:row];
case 2:{
return [self.yearArray objectAtIndex:row];
}
default:
break;
}
return @"";
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
NSLog(@"selected row:%d , component:%d" , row,component);
}