我有一个UIPickerView,当放在主视图上时效果很好。但是,只要我将其放入子UIView(为了帮助视觉放置元素),交互就会完全停止。 UIPickerView仍然可以正确接收所有数据,只是没有交互。
如果我使用故事板将UIPickerView从UIView中取出,它就可以立即使用。
- (void)viewDidLoad
{
[super viewDidLoad];
// Add provinces into array
[self.provinceView setHidden:YES];
isVisible = NO;
self.provinceArray = [[NSArray alloc] initWithObjects:@"Alberta",@"British Columbia",@"Manitoba",@"New Brunswick",@"Newfoundland and Labrador",@"Northwest Territories",@"Nova Scotia",@"Nunavut",@"Ontario",@"Prince Edward Island",@"Quebec",@"Saskatchewan",@"Yukon",nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return [self.provinceArray count];
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 0,(pickerView.frame.size.width-40), 44)];
label.textColor = [UIColor colorWithRed:0.035 green:0.094 blue:0.345 alpha:1.0];
label.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
label.text = [self.provinceArray objectAtIndex:row];
return label;
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
self.provinceLabel.text = [self.provinceArray objectAtIndex:row];
}
答案 0 :(得分:1)
查看此帖子 - > UIPickerView in UITableView doesn't react to touch in lower half of cell
你把子视图带到了前景吗?