现在我的UITableViewController中有2个不同的UIPickerView。我只是在敲击桌子上的某些细胞时才显示它们。我试图做的是每当我触摸采摘者时隐藏采摘者。是否有委托方法或类似的东西来实现这一目标?我更喜欢将我的控制器保持为UITableViewController而不是简单的UIViewController,因为我在其中一个单元格中有一个textView,并且在UIViewController中键盘显示之后滚动太多了。
提前致谢。
答案 0 :(得分:1)
其中一个可能的解决方案是,当点击特定单元格并处理选择器(呈现选择器)时,可以在tableview上插入一个名为MASK View的视图。 (使用Frame作为self.tableview.frame - yourPicker.frame.size.height)。现在,当你点击这个视图时,你可以按照以下方式处理它
-(void)showMaskView{
if (!viewMaskView) {
CGRect viewRect = CGRectMake(0, 0, self.tableView.frame.size.width, self.tableView.frame.size.height - yourPicker.frame.size.height);
viewMaskView = [[MaskView alloc] initWithFrame:viewRect];
viewMaskView.delegate = self;
}
[self.view addSubview:viewMaskView];
[self.view bringSubviewToFront:viewMaskView];
}
-(void)removeMaskView{
if (viewMaskView) {
[viewMaskView removeFromSuperview];
}
//Remove the Picker
}
在MaskView类中,您可以按如下方式处理触摸
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
if(self.delegate && [self.delegate respondsToSelector:@selector(removeMaskView)])
[self.delegate removeMaskView];
}
您可以在图片中的Picker上看到彩色遮罩视图。点击它会移除选择器。