Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UIPickerView get";点击";元素?_Iphone_Xcode_Uipickerview - Fatal编程技术网

Iphone UIPickerView get";点击";元素?

Iphone UIPickerView get";点击";元素?,iphone,xcode,uipickerview,Iphone,Xcode,Uipickerview,我使用旋转的UIPickerView来水平使用它。 到目前为止,这一切都很好 现在我想获取“单击”UIPickerView行的视图/标题。 代表给了我一个机会,当选取者 选择一行。我不希望在选择它时发生任何事件,我需要单击它的事件 有趣的是,我已经可以点击元素了。我没有加任何按钮或其他东西。 “单击”的元素/行会像按钮一样高亮显示。但是我应该将事件侦听器附加到哪里呢?或者我怎样才能得到这些事件 我还尝试将按钮作为视图添加到uipickerview中。到目前为止,这是有效的,但我无法单击任何按钮

我使用旋转的UIPickerView来水平使用它。 到目前为止,这一切都很好

现在我想获取“单击”UIPickerView行的视图/标题。 代表给了我一个机会,当选取者 选择一行。我不希望在选择它时发生任何事件,我需要单击它的事件

有趣的是,我已经可以点击元素了。我没有加任何按钮或其他东西。 “单击”的元素/行会像按钮一样高亮显示。但是我应该将事件侦听器附加到哪里呢?或者我怎样才能得到这些事件

我还尝试将按钮作为视图添加到uipickerview中。到目前为止,这是有效的,但我无法单击任何按钮

我是否需要UIPickerView行中的按钮作为视图来获取touchupinside事件或 我可以使用UIPickerView的普通行元素来获取这样的事件吗


谢谢你的帮助

单击某个图元时,将自动选择该图元。因此,SeleCeetedRow方法将足够好,而且,它将在刷卡时为您提供正确的元素(这在“单击”方法中不会发生)

要获取UIPickerView事件,您可能需要将控制器设置为符合UIPickerViewDataSource和UIPickerViewDelegate协议,并将选择器的委托和数据源设置为控制器。通过这种方式,您可以使用如下方法设置pickerView的内容

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
并获得活动:

– selectedRowInComponent:

您可以自定义pickerView并继承其触摸事件方法

- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event {
    if (!self.dragging) {
    [self.nextResponder touchesEnded: touches withEvent:event]; 
    }       
    //here u can keep track of touch event(click ,double click)
    [super touchesEnded: touches withEvent: event];
}
这很简单:

- (void)viewDidLoad {
    picker.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGesture =[[UITapGestureRecognizer alloc] initWithTarget:self 
                                                                                        action:@selector(pickerTap)];
    [picker addGestureRecognizer:tapGesture];
    [tapGesture release];
}

- (void)pickerTap {
    NSLog(@"Picker tapped"); 
}
您不需要为UIPickerView创建子类。

检查,它可能不是您正在寻找的确切解决方案,但它有帮助


我最初通过在每个选择器项中添加一个透明按钮来实现点击选择,该按钮的行索引作为标记。它在iOS 7上不再工作,必须找到新的解决方案。

好的,我想这应该可以,但我需要一个扩展uipickerview的类,对吗?嗯,也许我真的应该建立一个自定义组件来解决这个问题,我只是认为它更容易,因为选择器得到了事件。太糟糕了…谢谢你的回答,但我想这个对我没什么帮助。用户应该使用pickerview选择一个值,然后通过直接单击它或多或少地提交他的选择。也许我只是添加了另一个按钮提交,但我想我可以使用行视图。。。