- (void) pickerView: (UIPickerView *) pickerView didSelectRow: (NSInteger) row inComponent: (NSInteger) component {
int selectedRow;
selectedRow = [pickerView selectedRowInComponent: component];
NSLog (@ "selectedRow =% i", selectedRow) ;/ / Here is the first pickerView debug the row values displayed correctly
if ([btn tag] == 1) {/ / Click the button tag 1, only one 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) {/ / Click the button tag 2, showing two pickerView, in another proxy function implements
if (component == AddressComponent) {/ / # define AddressComponent 0 first pickerView
if (selectedRow == 0) {
NSLog (@ "Beijing");
sectionData = [[NSMutableArray alloc] initWithArray: sectionDataOfBeijing];
[AddressView reloadComponent: SectionComponent];
}
else if (selectedRow == 1) {
NSLog (@ "Shanghai");
sectionData = [[NSMutableArray alloc] initWithArray: sectionDataOfShanghai];
[AddressView reloadComponent: SectionComponent];
}
else if (selectedRow == 2) {
NSLog (@ "Shenzhen");
sectionData = [[NSMutableArray alloc] initWithArray: sectionDataOfShenzhen];
[AddressView reloadComponent: SectionComponent];
}
else if (selectedRow == 3) {
NSLog (@ "Guangzhou");
sectionData = [[NSMutableArray alloc] initWithArray: sectionDataOfGuangzhou];
[AddressView reloadComponent: SectionComponent];
}
}
else if (component == SectionComponent) {/ / define SectionComponent 1 second pickerView
int selectedSectionRow;
selectedSectionRow = [pickerView selectedRowInComponent: SectionComponent];
NSLog (@ "(selectedRow =% i, selectedSectionRow =% i)", selectedRow, selectedSectionRow);
/ / This is the value of the two pickerView debugging was selected row, and do not know why, selectedRow did not save the last record,
/ / Even if I set it to a static does not work, only when the (0,0), (11), (2,2), (3,3) ... when you order the correct treatment.
if (selectedSectionRow == 0 && selectedRow == 0) / / This can be
{
NSLog (@ "Beijing Beijing 1");
[Btn setTitle: @ "Beijing Beijing 1" forState: nil];
[AddressView removeFromSuperview];
}
else if (selectedSectionRow == 0 && selectedRow == 1) {/ / When my second pickerView election Shanghai 时 1, btn the title into the "Beijing Beijing a" print the value of two variables (0 , 0)
NSLog (@ "Shanghai Shanghai 1");
[Btn setTitle: @ "" forState: nil];
[AddressView removeFromSuperview];
}
else if (selectedSectionRow == 1 && selectedRow == 1) {
NSLog (@ "Shanghai Shanghai 2");
[Btn setTitle: @ "Shanghai Shanghai 2" forState: nil];
[AddressView removeFromSuperview];
}
else if (selectedSectionRow == 0 && selectedRow == 2) {
/ / As long as the value is 0, the value of selectedSectionRow selectedRow is also 0, selectedSectionRow is 1, the value is 1
also selectedRow
NSLog (@ "Shenzhen Shenzhen 1");
[Btn setTitle: @ "Shenzhen Shenzhen 1" forState: nil];
[AddressView removeFromSuperview];
}
else if (selectedSectionRow == 1 && selectedRow == 2) {
NSLog (@ "in Shenzhen, Shenzhen 2");
[Btn setTitle: @ "Shenzhen Shenzhen 2" forState: nil];
[AddressView removeFromSuperview];
}
else if (selectedSectionRow == 2 && selectedRow == 2) {
NSLog (@ "Shenzhen Shenzhen 3");
[Btn setTitle: @ "Shenzhen Shenzhen 3" forState: nil];
[AddressView removeFromSuperview];
}
else if (selectedSectionRow == 0 && selectedRow == 3) {
NSLog (@ "Guangzhou Guangzhou 1");
[Btn setTitle: @ "Guangzhou Guangzhou 1" forState: nil];
[AddressView removeFromSuperview];
}
else if (selectedSectionRow == 1 && selectedRow == 3) {
NSLog (@ "Guangzhou Guangzhou 2");
[Btn setTitle: @ "Guangzhou Guangzhou 2" forState: nil];
[AddressView removeFromSuperview];
}
else if (selectedSectionRow == 2 && selectedRow == 3) {
NSLog (@ "Guangzhou Guangzhou 3");
[Btn setTitle: @ "Guangzhou Guangzhou 3" forState: nil];
[AddressView removeFromSuperview];
}
else if (selectedSectionRow == 3 && selectedRow == 3) {
NSLog (@ "Guangzhou Guangzhou 4");
[Btn setTitle: @ "Guangzhou Guangzhou 4" forState: nil];
[AddressView removeFromSuperview];
}
}
}
} Now my second pickerView content will vary with the value of the first selected row pickerView change. But in the second election pickerView can not choose correctly.
Probably many heroes will say to me, do not think about myself, it has been posting asked, but I really want a day! I always follow my logic to think, it has been trapped inside get out. There is really no other way, because the company doing iPhone development on one person, only on the Internet asking you. Thank you!
Reply:
Remove the first one, look at the second act itself is correct.
tag is set correctly.
To narrow the scope of the problem a little bit.
Reply:
Sorry can not help you a favor, but I think you can at least use the switch-case instead of what so many people dazzled the if-else it.
Reply:
tag set is not a problem, but the first one removed, you can not update the display of the contents of the second pickerView according to the first. I want two exchange it. But only to try to work tomorrow!
Reply:
Man kind, you're right, with the switch-case will be much better, I changed tomorrow, thank you for reminding me!
Reply:
Understand drifting
Reply:
Solve the problem, is my own carelessness
I re-define two variables [btn tag] == 2 of handlers:
int selectedAddressRow;
selectedAddressRow = [ addressView selectedRowInComponent: AddressComponent];
int selectedSectionRow;
selectedSectionRow == [ addressView selectedRowInComponent: SectionComponent];
After further processing on the line!
Pick up the lessons, we must seriously! ! !
Reply:
Reply
To cheer every time, ha ha, this issue is resolved ~
Reply:
Oh, fix it. . Recently I was watching the network and database hey. . .
Reply:
Be patient, much to practice in order to find the problem ~ Come on!
No comments:
Post a Comment