29,028
社区成员
发帖
与我相关
我的任务
分享
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
int selectedRow;
selectedRow = [pickerView selectedRowInComponent:component];
NSLog(@"selectedRow = %i", selectedRow);//这里调试的是第一个pickerView的row的值,显示正确
if([btn tag] ==1){ //点击tag为1的按钮,只显示一个pickerView
if (selectedRow == 0) {
NSLog(@"3KM");
[btn setTitle:@"3公里" forState:nil];
}
else if(selectedRow == 1){
NSLog(@"2KM");
[btn setTitle:@"2公里" forState:nil];
}
else if(selectedRow == 2){
NSLog(@"1KM");
[btn setTitle:@"1公里" forState:nil];
}
else{
NSLog(@"500m");
[btn setTitle:@"500米" forState:nil];
}
[distanceView removeFromSuperview];
}
else if([btn tag] == 2){ //点击tag为2的按钮,显示两个pickerView,在另一个代理函数中实现了
if(component == AddressComponent){ // #define AddressComponent 0 第一个pickerView
if(selectedRow == 0){
NSLog(@"北京");
sectionData = [[NSMutableArray alloc] initWithArray:sectionDataOfBeijing];
[addressView reloadComponent:SectionComponent];
}
else if(selectedRow == 1){
NSLog(@"上海");
sectionData = [[NSMutableArray alloc] initWithArray:sectionDataOfShanghai];
[addressView reloadComponent:SectionComponent];
}
else if(selectedRow == 2){
NSLog(@"深圳");
sectionData = [[NSMutableArray alloc] initWithArray:sectionDataOfShenzhen];
[addressView reloadComponent:SectionComponent];
}
else if(selectedRow == 3){
NSLog(@"广州");
sectionData = [[NSMutableArray alloc] initWithArray:sectionDataOfGuangzhou];
[addressView reloadComponent:SectionComponent];
}
}
else if(component == SectionComponent){ //define SectionComponent 1 第二个pickerView
int selectedSectionRow;
selectedSectionRow = [pickerView selectedRowInComponent:SectionComponent];
NSLog(@"(selectedRow = %i, selectedSectionRow = %i)", selectedRow,selectedSectionRow);
//这里调试的是两个pickerView中被选定row的值,不知道为什么,selectedRow没有保存上次的记录,
//即使我把它设成是static也不行,只有当(0,0),(11),(2,2),(3,3)…时才能正确的处理。
if(selectedSectionRow == 0 && selectedRow == 0) //这个可以
{
NSLog(@"北京 北京1");
[btn setTitle:@"北京 北京1" forState:nil];
[addressView removeFromSuperview];
}
else if(selectedSectionRow == 0 && selectedRow == 1){ //当我第二个pickerView选上海1时,btn的title变为了"北京 北京1",打印两个变量的值为(0,0)
NSLog(@"上海 上海1");
[btn setTitle:@"" forState:nil];
[addressView removeFromSuperview];
}
else if(selectedSectionRow == 1 && selectedRow == 1){
NSLog(@"上海 上海2");
[btn setTitle:@"上海 上海2" forState:nil];
[addressView removeFromSuperview];
}
else if(selectedSectionRow == 0 && selectedRow == 2){
//只要是selectedSectionRow的值为0,则selectedRow的值也为0,selectedSectionRow的值为1,selectedRow的值也为1
NSLog(@"深圳 深圳1");
[btn setTitle:@"深圳 深圳1" forState:nil];
[addressView removeFromSuperview];
}
else if(selectedSectionRow == 1 && selectedRow == 2){
NSLog(@"深圳 深圳2");
[btn setTitle:@"深圳 深圳2" forState:nil];
[addressView removeFromSuperview];
}
else if(selectedSectionRow == 2 && selectedRow == 2){
NSLog(@"深圳 深圳3");
[btn setTitle:@"深圳 深圳3" forState:nil];
[addressView removeFromSuperview];
}
else if(selectedSectionRow == 0 && selectedRow == 3){
NSLog(@"广州 广州1");
[btn setTitle:@"广州 广州1" forState:nil];
[addressView removeFromSuperview];
}
else if(selectedSectionRow == 1 && selectedRow == 3){
NSLog(@"广州 广州2");
[btn setTitle:@"广州 广州2" forState:nil];
[addressView removeFromSuperview];
}
else if(selectedSectionRow == 2 && selectedRow == 3){
NSLog(@"广州 广州3");
[btn setTitle:@"广州 广州3" forState:nil];
[addressView removeFromSuperview];
}
else if(selectedSectionRow == 3 && selectedRow == 3){
NSLog(@"广州 广州4");
[btn setTitle:@"广州 广州4" forState:nil];
[addressView removeFromSuperview];
}
}
}
}