Jig*_*tel 52 iphone uipickerview uiactionsheet ios ios8
我正在补充UIPickerView
,UIActionsheet
但它的工作完美,ios 7
但没有工作ios 8
.请帮我解决这个问题.
在这里我附上了截图.
谢谢
我正在使用以下代码.
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)];
}
}
Run Code Online (Sandbox Code Playgroud)
Are*_*lko 21
它不起作用,因为Apple改变了内部实施UIActionSheet
.请参阅文档:
子类注释
UIActionSheet不是设计为子类,也不 应该为其层次结构添加视图.如果您需要提供比UIActionSheet API提供的更多自定义的工作表,您可以创建自己的工作表并使用presentViewController以模态方式呈现它:animated:completion:.
Nad*_*mal 21
根据Apple文档,
重要提示:
UIActionSheet
在iOS的8已被弃用(请注意,UIActionSheetDelegate
也已经过时.)创建和iOS 8的管理动作片,后来,改用UIAlertController
了preferredStyle
的UIAlertControllerStyleActionSheet
.
例如:
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];
Run Code Online (Sandbox Code Playgroud)
sky*_*der 11
有一个开箱即用的解决方案具有完全相同的行为 - ActionSheetPicker-3.0
使用原始版本UIActionsheet
,但在iOS 8版本中,我升级此项目并用简单视图替换UIActionsheet,但动画和视图看起来完全相同.
小智 8
我也发现了这个问题,我有一个解决方案,希望它可以帮到你..
您可以在此处下载示例代码:https: //www.dropbox.com/s/yrzq3hg66pjwjwn/UIPickerViewForIos8.zip?dl=0
@interface ViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>{
UIView *maskView;
UIPickerView *_providerPickerView;
UIToolbar *_providerToolbar;
}
- (void) createPickerView {
maskView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[maskView setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5]];
[self.view addSubview:maskView];
_providerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 344, self.view.bounds.size.width, 44)];
UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissActionSheet:)];
_providerToolbar.items = @[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], done];
_providerToolbar.barStyle = UIBarStyleBlackOpaque;
[self.view addSubview:_providerToolbar];
_providerPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 300, 0, 0)];
_providerPickerView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.5];
_providerPickerView.showsSelectionIndicator = YES;
_providerPickerView.dataSource = self;
_providerPickerView.delegate = self;
[self.view addSubview:_providerPickerView];
}
- (void)dismissActionSheet:(id)sender{
[maskView removeFromSuperview];
[_providerPickerView removeFromSuperview];
[_providerToolbar removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
28768 次 |
最近记录: |