Search code examples
iosswiftuitableviewuipickerview

Showing UIPickerView when cell is selected


For my app I’m implementing in-app settings using tableView with Dynamic prototype cells. Inside cell I’m showing main title and sub title. What I would like to achieve is when user clicks on one of the cells (that represents specific settings) the pickerView will slide from the bottom of the screen showing the options that user can pick. I’ve seen few tutorials where this pickerView is presented inside a cell as it is e.g. in iOS calendar app but I don’t need that – all will be fine if it will slide from the bottom actually in a same way as it is when you are having pickerView as inputView for your text field (e.g. textField.inputView = pickerView) and click to the text field. I appreciate any help you can provide guys! Thanks in advance!


Solution

  • You can create a custom view xib in which you can have pickerView,when user click on cell just show the custom view with animation.
    
    viewPicker = CGRectMake(0, 490, 320, 460);
    
    For the animation from bottom to top add below:
    
    [UIView animateWithDuration:0.5
                          delay:0.1
                        options: UIViewAnimationCurveEaseIn
                     animations:^{
                         viewPicker.frame = CGRectMake(0, 0, 320, 460);
                     } 
                     completion:^(BOOL finished){
                     }];
    [self.view addSubview:viewPicker];
    
    
    For removing the view
    
    [UIView animateWithDuration:1.5
                                  delay:0.5
                                options: UIViewAnimationCurveEaseIn
                             animations:^{
        viewPicker.frame = CGRectMake(0, 490, 320, 460);
                             }
                             completion:^(BOOL finished){
                                 if (finished)
                                     [viewPicker removeFromSuperview];
                             }];