如何阅读uipicker多个组件时更改一个组件
问题描述:
我有一个3组件ui选择器索引,日期和时间的咨询。如何阅读uipicker多个组件时更改一个组件
我想在第一个组件被改变时读取第二和第三个组件的值。
当组件1被更改时,应该如何阅读UIPicker中的第二和第三组件?
[email protected][@"Sunday",@"Monday",@"Tuesday",@"Wednesday",@"Thursday",@"Friday",@"Saturday"];
[email protected][@"1",@"2",@"3",@"4",@"5",@"6",@"7"];
[email protected][@"9:00 AM",@"11:00 AM"];
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if(component == 0){
_labelValueIndex.text = [self.indexes objectAtIndex:row];
// When component 1 is spinned read component 2 and component 3 value even if they are not spinned
[days objectAtIndex:row];// incorrect value as row variable is like global if i select indexes[1] . i also get days[1] and timeOfConsultation [1]
// How to read component 2 and component 3 value from component1 change event
}else if (component == 1){
labelValueBookingDay.text = [days objectAtIndex:row];
}
else{
labelValueTimeOfConsultation.text = [timeOfConsultation objectAtIndex:row];
}
}
答
使用此代码 -
NSString *YourselectedTitle = [self.yourArrayName objectAtIndex:[self.yourPickerName selectedRowInComponent:1]];
NSLog(@"%@", YourselectedTitle);
希望这有助于!