Is there any way to add UIPickerView into UIAlertController (Alert or ActionSheet) in Swift?

后端 未结 11 1330
旧巷少年郎
旧巷少年郎 2020-12-01 06:16

I\'m totally new to swift (and iOS programming at all), but I started messing around with it (it wasn\'t a good idea when everything is still beta version :D). So I tried to

11条回答
  •  离开以前
    2020-12-01 07:09

    alertController = [UIAlertController alertControllerWithTitle:@" \n\n\n\n\n\n\n\n\n\n"
                                                          message:@""
                                                   preferredStyle:UIAlertControllerStyleActionSheet];
    
    closePicker = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Cancel"]];
    closePicker.momentary = YES;
    closePicker.frame = CGRectMake(25, 0.0f, 50.0f, 30.0f);
    closePicker.segmentedControlStyle = UISegmentedControlStyleBar;
    closePicker.tintColor = [UIColor blackColor];
    [closePicker addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
    [alertController.view addSubview:closePicker];
    
    
    UIPickerView *pickerFiliter=[[UIPickerView alloc]init];
    pickerFiliter = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 40.0, 320.0, 120.0)];
    pickerFiliter.showsSelectionIndicator = YES;
    pickerFiliter.dataSource = self;
    pickerFiliter.delegate = self;
    
    [alertController.view addSubview:pickerFiliter];
    
    
    [self presentViewController:alertController animated:YES completion:nil];
    
    
    - (IBAction)dismissActionSheet:(id)sender 
     {
    
        [alertController dismissViewControllerAnimated:YES completion:nil];
    
     }
    

提交回复
热议问题