【问题标题】:UIPickerView not working in sub UIViewUIPickerView 在子 UIView 中不起作用
【发布时间】:2013-10-27 15:23:24
【问题描述】:

我有一个 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];
}

【问题讨论】:

  • 您的子视图 userInteractionEnabled=yes 吗?

标签: ios uipickerview


【解决方案1】:

查看这篇文章 --> UIPickerView in UITableView doesn't react to touch in lower half of cell

你把子视图带到前台了吗?

【讨论】:

  • 抱歉发现问题。由于某种原因,重新定位视图只是重新定位视图的内容。看起来我在解决 CGRect 问题时遇到了新问题。
  • 我使用“边界”而不是“框架”来重新定位。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-19
  • 2011-07-22
  • 2023-03-15
相关资源
最近更新 更多