views:

411

answers:

2

Hi.

I'm trying to use a UIPicker View with a behavior somehow different of what's usually seen in iPhone code examples.

What I want to do is to allow users to scroll through the picker contents, but not to select a picker's row automatically (using the "didSelectRow" method from picker's delegate). Instead, I want to allow the user to touch the center row of the picker, which gets highlighted, and becomes the selection.

Is there any way to achieve this?

Thanks in advance.

A: 

There are only 2 delegates for UIPickerView.

So, we can use only 7 methods to control UIPickerView by delegate.

– pickerView:rowHeightForComponent:
– pickerView:widthForComponent:
– pickerView:titleForRow:forComponent:
– pickerView:viewForRow:forComponent:reusingView:
– pickerView:didSelectRow:inComponent:
– numberOfComponentsInPickerView:
– pickerView:numberOfRowsInComponent:

that'all.

In UITableViewDelegate case, there are more methods for UITableView for managing selections. such as, – tableView:willSelectRowAtIndexPath:
– tableView:didSelectRowAtIndexPath:
– tableView:willDeselectRowAtIndexPath:
– tableView:didDeselectRowAtIndexPath:

However...

In UIPickerViewDelegate case, there is only 1 method for responding to row selection.

– pickerView:didSelectRow:inComponent:

cappuccino
that's what I was thinking. I've seen applications doing what I want, but I suppose i'm doing it some other way. Thanks anyway.
camilo
A: 
  1. make a new UIControl

    • same position as the UIPickerView
    • [yourcontrol setBackGroundColor: [UIColor clearColor]];
  2. make a method

- (IBAction) pickerControlTapped 
{
    [yourpicker selectRow: rand()% yourpickersize
              inComponent: 0
                 animated: YES];
}

.3. make a connection between 1 and 2

 
[yourcontrol addTarget: self 
                action: @selector(pickerControlTapped) 
      forControlEvents: UIControlEventTouchUpInsied];
cappuccino
Thanks a lot. I'll try it now.
camilo