我正在使用UIPickerView從所選數據中進行選取。PickerView無法正常工作
- (void)viewDidLoad
{
myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 640, 320, 200)];
myPickerView.delegate = self;
myPickerView.showsSelectionIndicator = YES;
[self.view addSubview:myPickerView];
UIToolbar *toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,44)];
[toolBar setBarStyle:UIBarStyleBlackOpaque];
UIBarButtonItem *barButtonDone = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleBordered target:self action:@selector(changeDateFromLabel:)];
toolBar.items = [[NSArray alloc] initWithObjects:barButtonDone,nil];
barButtonDone.tintColor=[UIColor blackColor];
}
和
(void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component {
// Handle the selection
NSLog(@"%d",row);
lbl.text=[ary objectAtIndex:row];
}
// tell the picker how many rows are available for a given component
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
NSUInteger numRows = 5;
return numRows;
}
// tell the picker how many components it will have
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel* tView = (UILabel*)view;
if (!tView){
tView = [[UILabel alloc] init];
// Setup label properties - frame, font, colors etc
tView.font=[UIFont systemFontOfSize:16.0f];
//adjustsFontSizeToFitWidth property to YES
// tView.adjustsFontSizeToFitWidth = YES;
}
// Fill the label text here
tView.text=[ary objectAtIndex:row];
[tView setLineBreakMode:NSLineBreakByCharWrapping];
[tView setNumberOfLines:0];
return tView;
}
,我動視了當標籤用戶點擊(標籤自來水事件):
-(void)labelTap{
v1.hidden=NO;
[UIView animateWithDuration:0.25 delay:0.0 options: UIViewAnimationOptionCurveEaseInOut
animations:^{
CGRect frm;
frm=self.view.frame;
frm.origin.y=frm.origin.y-400;
self.view.frame=frm;
// self.view.frame=CGRectMake(0, -30, 320, 200);
//v1.frame=CGRectMake(0, 360, 320, 200);
// v1.backgroundColor=[UIColor blackColor];
}
completion:^(BOOL finished){
if(finished) {NSLog(@"Finished end !!!!!");}
}];
}
但是當我點擊標籤UIPickerView顯示屏上,但我無法從中選擇數據。它只是顯示UIPickerView。
您使用tView,並使用didSelectRow:in lbl。 您使用哪個標籤? – payal