Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add UIPickerView in UIActionSheet from IOS 8 not working

I am adding UIPickerView to UIActionsheet but its working perfectally in ios 7 but not working in ios 8. Please help me to solve that.

Here i attached screenshot for that.enter image description here

Thanks

I am using following code for that.

UIActionSheet *actionSheet; NSString *pickerType;  - (void)createActionSheet {      if (actionSheet == nil) {         // setup actionsheet to contain the UIPicker         actionSheet = [[UIActionSheet alloc] initWithTitle:@"Please select" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];         actionSheet.backgroundColor = [UIColor clearColor];          UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];         pickerToolbar.barStyle = UIBarStyleBlackOpaque;         [pickerToolbar sizeToFit];          UIImageView *imageObj = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 40)];         imageObj.image = [UIImage imageNamed:@"header.png"];         [pickerToolbar addSubview:imageObj];          UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];         [cancelBtn addTarget:self action:@selector(pickerCancel:)forControlEvents:UIControlEventTouchDown];         // [cancelBtn setImage:[UIImage imageNamed:@"btnInviteCancel.png"] forState:UIControlStateNormal];         [cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal];          cancelBtn.frame = CGRectMake(7.0, 7.0, 65.0, 25.0);         [pickerToolbar addSubview:cancelBtn];          UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];         [doneBtn addTarget:self action:@selector(pickerDone:)forControlEvents:UIControlEventTouchDown];         //[doneBtn setImage:[UIImage imageNamed:@"btnInviteDone.png"] forState:UIControlStateNormal];         [doneBtn setTitle:@"Done" forState:UIControlStateNormal];         doneBtn.frame = CGRectMake(258.0, 7.0, 55.0, 25.0);         [pickerToolbar addSubview:doneBtn];          [actionSheet addSubview:pickerToolbar];         [pickerToolbar release];           UIPickerView *chPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 200.0)];         chPicker.dataSource = self;         chPicker.delegate = self;         chPicker.showsSelectionIndicator = YES;         [chPicker selectRow:0 inComponent:0 animated:YES];         [actionSheet addSubview:chPicker];         [chPicker release];          [actionSheet showInView:self.view];         [actionSheet setBounds:CGRectMake(0,0,320, 464)];     } } 
like image 253
Jignesh Patel Avatar asked Jun 23 '14 12:06

Jignesh Patel


1 Answers

Per the Apple docs,

Important: UIActionSheet is deprecated in iOS 8. (Note that UIActionSheetDelegate is also deprecated.) To create and manage action sheets in iOS 8 and later, instead use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet.

Link to documentation for UIAlertController

For example:

     UIAlertController * searchActionSheet=[UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];                  [ searchActionSheet.view setBounds:CGRectMake(7, 180, self.view.frame.size.width, 470)];                  //yourView represent the view that contains UIPickerView and toolbar                 [searchActionSheet.view addSubview:self.yourView];                 [self presentViewController:searchActionSheet animated:YES completion:nil]; 
like image 168
Nada Gamal Avatar answered Oct 09 '22 11:10

Nada Gamal