views:

139

answers:

2

Hey Guys,

im using a rotated UIPickerView to use it horizontal. This works fine so far.

Now i want to get the View/Title of the "clicked" UIPickerView row. The Delegate gives me the opportunity to get the "selectedRow" when the Picker selects a row. I want no event while selecting it i need the event of clicking it.

The funny thing is, i can already click the elements. i added no button or anything else. the "clicked" elements/row get highlighted like a button. But where should i attach the event listener? or how can i get any of this events?

i also tried to add buttons as view to the uipickerview. This works so far, but i can not click any button.

Do i need a button as View in a UIPickerView row to get the touchupinside-event or can i use the normal row-element of a UIPickerView to get such an event?

thx for any help!

A: 

When you click an element, it will be automatically selected. So, the selecetedRow method will be good enough, also, it will give you the right element when swiping (which will not happen with the "click" approach).

To get the UIPickerView events you may want to set your controller to conform to the UIPickerViewDataSource and UIPickerViewDelegate protocols and set the picker's delegate and datasource to the controller. This way you can set the content of the pickerView with methods like

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView

and get the event:

– selectedRowInComponent:
dkk
thx for answering but i guess this one wont help me much. The user should select a value with the pickerview and then more or less submit his selection by clicking on it directly. maybe i just add another button to submit, but i thought i can use the row-view...
Phil
A: 

u can customize the pickerView and inherit their touch event method . `- (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];

}`

pawan.mangal
Ok, i guess this should work, but i need a class extending a uipickerview right? Mh, maybe i should really build a custom component to solve this issue, i just thought its easier because the picker gets the events. too bad...
Phil