我在一个UIPickerView中有一个UIActionSheet,并在这里以其他许多人建议的方式这样做了:
Add UIPickerView & a Button in Action sheet - How?
how to add UIPickerView in UIActionSheet
到目前为止,在iOS 7上测试我的应用程序时,这些解决方案一直运行良好。它仍然有效,但在运行时,我在Xcode中收到了许多“无效上下文0x0”警告。
这些错误也带来了一个好消息: CGContextSetFillColorWithColor:无效上下文0x0。这是一个严重的错误。此应用程序或它使用的库使用无效上下文,从而导致系统稳定性和可靠性的总体下降。这个通知是礼貌的:请解决这个问题。这将成为一个致命的错误,在即将更新。
这是苹果最终想要停止这种解决方案,还是它是什么,我们可以解决或修复?
发布于 2013-09-27 09:40:40
发布于 2013-10-01 08:35:07
解决此“无效上下文0x0”警告的方法是在UIActionSheet中插入一个非零标题( nil按钮也可以解决错误,但会导致可视化的人工制品)。
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@""
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];然后,您将需要调整actionsheet的框架以使其在iOS7和以前的版本中正确定位(确保在showInView方法之后这样做)。
CGRect newFrame = actionSheet.frame;
newFrame = self.view.bounds.size.height - myCustomPicker.frame.size.height;
newFrame = myCustomPicker.frame.size.height;
actionSheet.frame = newFrame;发布于 2014-01-07 11:10:36
-(void)viewDidLoad
{
[super viewDidLoad];
// Make Your own Action sheet
myCustomeActionSheet=[[UIView alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height+1,self.view.frame.size.width,215)];
myCustomeActionSheet.backgroundColor=[UIColor whiteColor];
[self.view addSubview:myCustomeActionSheet];
}//使用此代码打开日期选择器或UiPicker视图
-(void)OpenActionSheet:(Boolean)isDatePickere
{
SelectedString=Nil;
if (datepickerView) {
[datepickerView removeFromSuperview];
datepickerView=Nil;
}
if (picker) {
[picker removeFromSuperview];
picker=Nil;
}
if (isDatePickere)
{
// Add the Datepicker
datepickerView= [[UIDatePicker alloc] init];
datepickerView.datePickerMode = UIDatePickerModeDateAndTime;
datepickerView.minimumDate=[NSDate date];
[myCustomeActionSheet addSubview:datepickerView];
}
else
{
// Add Picker View
picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,40, 320, 216)];
picker.showsSelectionIndicator=YES;
picker.dataSource = self;
picker.delegate = self;
[myCustomeActionSheet addSubview:picker];
}
UIToolbar *tools=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 0,320,40)];
tools.barStyle=UIBarStyleBlackOpaque;
[myCustomeActionSheet addSubview:tools];
UIBarButtonItem *doneButton=[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(btnActinDoneClicked)];
doneButton.imageInsets=UIEdgeInsetsMake(200, 6, 50, 25);
UIBarButtonItem *CancelButton=[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(btnActinCancelClicked)];
UIBarButtonItem *flexSpace= [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSArray *array = [[NSArray alloc]initWithObjects:CancelButton,flexSpace,flexSpace,doneButton,nil];
[tools setItems:array];
//picker title
UILabel *lblPickerTitle=[[UILabel alloc]initWithFrame:CGRectMake(60,8, 200, 25)];
lblPickerTitle.text=@"Select";
lblPickerTitle.backgroundColor=[UIColor clearColor];
lblPickerTitle.textColor=[UIColor whiteColor];
lblPickerTitle.textAlignment=NSTextAlignmentCenter;
lblPickerTitle.font=[UIFont boldSystemFontOfSize:15];
[tools addSubview:lblPickerTitle];
[UIView animateWithDuration:0.5 animations:^{
myCustomeActionSheet.frame=CGRectMake(0,self.view.frame.size.height-myCustomeActionSheet.frame.size.height,myCustomeActionSheet.frame.size.width,myCustomeActionSheet.frame.size.height);
} completion:^(BOOL finished)
{
}];
}pragma -mark酒吧按钮动作
-(void)btnActinDoneClicked
{
if (SelectedString==Nil)
{
SelectedString=[pickerArrayList objectAtIndex:0];
}
if (datepickerView)
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSLocale *posix = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[dateFormatter setLocale:posix];
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
[dateFormatter setDateFormat:@"DD/MM/yy hh:mm a"];
[selectedButton setTitle:[dateFormatter stringFromDate:datepickerView.date] forState:UIControlStateNormal];
}
else
[selectedButton setTitle:SelectedString forState:UIControlStateNormal];
[self performSelector:@selector(btnActinCancelClicked) withObject:nil afterDelay:0.10];
}
-(void)btnActinCancelClicked
{
[UIView animateWithDuration:0.5 animations:^{
viewActiobSheetView.frame=CGRectMake(0,self.view.frame.size.height+1,self.view.frame.size.width,viewActiobSheetView.frame.size.height);
}
completion:^(BOOL finished)
{
[datepickerView removeFromSuperview];
[picker removeFromSuperview];
datepickerView=Nil;
picker=Nil;
}];
}pragma -mark PickerView代表
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent: (NSInteger)component reusingView:(UIView *)view
{
UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
label.text=[pickerArrayList objectAtIndex:row];
label.textAlignment=NSTextAlignmentCenter;
label.textColor=[UIColor blackColor];
return label;
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [pickerArrayList count];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
SelectedString=[pickerArrayList objectAtIndex:row];
}https://stackoverflow.com/questions/19011170
复制相似问题