how to put this code below?
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSString *year = [dateYear objectAtIndex:[picker selectedRowInComponent:0]];
NSString *month = [dateMonth objectAtIndex:[picker selectedRowInComponent:1]];
NSString *day = [dateDay objectAtIndex:[picker selectedRowInComponent:2]];
labelDate1.text = [year stringByAppendingFormat:@" : %@ : %@", month, day];
}
into here?
- (IBAction)setDateBtn1:(id)sender {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
viewPicker.frame = CGRectMake(0, 0, 320, 460);
[UIView commitAnimations];
}
My problem is, i have two button setDateBtn1 for labelDate1 and setDateBtn2 for labelDate2, both button calls one pickerView for input data that show at each label. After selecting date, it appears in labelDate1 only, no matter what button i call my pickerview, but what i want is setDateBtn1 for labelDate1 and setDateBtn2 for labelDate2. I hope you understand my english. For any help, thank you so much.
If I understand your question correctly, you have one picker method but two buttons (or labels) where either of which can bring up your picker. Selecting something in the picker should set label1 or label2.
So… here’s an opportunity for you to make use of the picker view’s “
tag” property.When bringing up the picker, set the “
viewPicker.tag” to “1” (for label 1) and “2” if the button for label 2 brings up the picker.Then, in your “
didSelectRow” function, you’ll know which label you’re doing the picking for. And you can do something like this:Hopefully I explained this well enough for you to keep going.