Search code examples
iphoneuipickerview

how to set indicator of picker view to specific value


My cell is containing a button when you click a button, the picker view will pop op just like an image below enter image description here

Question :

How can I change so that the indicator will move to the correct value which is shown in my button.

For example, my button is showing 8 and if you tap on it, the picker view will be popped up with indicator choosing 8.

If you know how to customize this. please advice me on this issue. Thanks


Solution

  • You can implement the following:

    - (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated
    

    You can use it by adding an IBAction for the button.

    -(IBAction)userTappedNumber{
        //Call your picker view's method here.
        [self.pickerView selectRow:8 inComponent:0 animated:YES];
    }
    

    For future reference try taking a look at Apple's references and searching for similar questions via google and the Stack Overflow search before asking simple questions. Apple's UIPickerView Class Reference