iOS应用程序中的选择器

时间:2017-04-25 05:37:16

标签: ios

如何创建用作选择器的视图控制器?它在当前上下文中从屏幕底部显示,并且仅覆盖屏幕的一部分。选择一个值后,会将其传递回在iOS中显示选择器的视图控制器。

3 个答案:

答案 0 :(得分:0)

在目标C中尝试:

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Success" message:@"Thank you for coming here" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
//define your custom action here or data passing here               
 [self dismissViewControllerAnimated:YES completion:nil];
            }];
            [alert addAction:okAction];
            [self presentViewController:alert animated:YES completion:nil];

答案 1 :(得分:0)

尝试使用以下有用的库:

https://github.com/madjid/MMPickerView

代码段

NSArray *strings = @[@"This", @"is", @"just", @"an array", @"of strings."];

  [MMPickerView showPickerViewInView:self.view
                         withStrings:strings
                         withOptions:nil
                          completion:^(NSString *selectedString) {
                            //selectedString is the return value which you can use as you wish
                            self.label.text = selectedString;
  }];

答案 2 :(得分:0)

添加UIViewController和您想要的设计..为该视图控制器提供一个Stroyboard ID ... 在选择器视图控制器类

中添加以下代码
check.php

当用户didSelectRowAtIndexPath ..

var mainVC : YourSendingClassName!

现在在你的发送者课程中,如果你想使用一个按钮从中创建一个动作...根据你的要求,按钮应该在底部..

在Button Action

中添加以下代码
   call self.dismiss(true , completion { 
self.mainVC.userPickedValue(theValueYouWannaPass)
})

动作后创建一个函数

   let sliderViewController =  storyboard?.instantiateViewController(withIdentifier: "YourStoryBoard ID") as! YourPickerClass
        sliderViewController.modalPresentationStyle = .popover
     //set width and height as you need   
        sliderViewController.preferredContentSize = CGSize(width: 253, height: 160)
        sliderViewController.mainVC = self

        let popoverMenuViewController = sliderViewController.popoverPresentationController
        popoverMenuViewController?.permittedArrowDirections = .down
        popoverMenuViewController?.delegate = self
        popoverMenuViewController?.sourceView = sender
        popoverMenuViewController?.sourceRect = sender.frame
        present(sliderViewController, animated: true, completion: nil)