从IOS 8在UIActionSheet中添加UIPickerView无法正常工作 [英] Add UIPickerView in UIActionSheet from IOS 8 not working
本文介绍了从IOS 8在UIActionSheet中添加UIPickerView无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将 UIPickerView
添加到 UIActionsheet
但是它在 ios 7中完美地工作
但不能在 ios 8
中工作。请帮我解决。
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.
这里我附上了截图。
谢谢
我正在使用以下代码。
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)];
}
}
推荐答案
Per Apple文档,
重要:
UIActionSheet
在iOS 8中已弃用。(请注意UIActionSheetDelegate
也已弃用。)要在iOS 8及更高版本中创建和管理操作表,请使用UIAlertController
并使用preferredStyle
UIAlertControllerStyleActionSheet
。
Important:
UIActionSheet
is deprecated in iOS 8. (Note thatUIActionSheetDelegate
is also deprecated.) To create and manage action sheets in iOS 8 and later, instead useUIAlertController
with apreferredStyle
ofUIAlertControllerStyleActionSheet
.
例如:
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];
这篇关于从IOS 8在UIActionSheet中添加UIPickerView无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文