首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在iOS 7中添加UIPickerView时,UIActionSheet中的上下文错误是否无效?

在iOS 7中添加UIPickerView时,UIActionSheet中的上下文错误是否无效?
EN

Stack Overflow用户
提问于 2013-09-25 17:11:04
回答 3查看 9.7K关注 0票数 9

我在一个UIPickerView中有一个UIActionSheet,并在这里以其他许多人建议的方式这样做了:

Add UIPickerView & a Button in Action sheet - How?

how to add UIPickerView in UIActionSheet

到目前为止,在iOS 7上测试我的应用程序时,这些解决方案一直运行良好。它仍然有效,但在运行时,我在Xcode中收到了许多“无效上下文0x0”警告。

这些错误也带来了一个好消息: CGContextSetFillColorWithColor:无效上下文0x0。这是一个严重的错误。此应用程序或它使用的库使用无效上下文,从而导致系统稳定性和可靠性的总体下降。这个通知是礼貌的:请解决这个问题。这将成为一个致命的错误,在即将更新。

这是苹果最终想要停止这种解决方案,还是它是什么,我们可以解决或修复?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-09-27 09:40:40

正如上面的注释所指出的那样,UIActionSheet并不是设计成子类或其他视图的。

更多信息请访问苹果公司:

2

一种方法是仔细查看DateCell示例代码并将其更改为使用UIPickerView:

2

票数 2
EN

Stack Overflow用户

发布于 2013-10-01 08:35:07

解决此“无效上下文0x0”警告的方法是在UIActionSheet中插入一个非零标题( nil按钮也可以解决错误,但会导致可视化的人工制品)。

代码语言:javascript
复制
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"" 
                                                         delegate:nil
                                                cancelButtonTitle:nil
                                           destructiveButtonTitle:nil
                                                otherButtonTitles:nil];

然后,您将需要调整actionsheet的框架以使其在iOS7和以前的版本中正确定位(确保在showInView方法之后这样做)。

代码语言:javascript
复制
CGRect newFrame = actionSheet.frame;
newFrame = self.view.bounds.size.height - myCustomPicker.frame.size.height;
newFrame = myCustomPicker.frame.size.height;
actionSheet.frame = newFrame;
票数 11
EN

Stack Overflow用户

发布于 2014-01-07 11:10:36

代码语言:javascript
复制
-(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视图

代码语言:javascript
复制
-(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酒吧按钮动作

代码语言:javascript
复制
-(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代表

代码语言:javascript
复制
 - (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];
   }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19011170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档