【问题标题】:UIActionSheet showInView give warning : invalid context 0x0UIActionSheet showInView 给出警告:无效上下文 0x0
【发布时间】:2014-02-28 05:53:53
【问题描述】:

我正在尝试在self.view.parentview 中显示 UIActionSheet。但我在运行时收到以下警告

<Error>: CGContextSetFillColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
<Error>: CGContextSetStrokeColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
<Error>: CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

代码如下

self.dobActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil,nil];
[self.dobActionSheet addSubview:self.doneForActionSheet];
[self.dobActionSheet addSubview:self.cancelForActionSheet];
[self.dobActionSheet addSubview:self.dobDatepicker];
[self.dobActionSheet showInView:self.parentViewController.view];

我已经设置了断点。但在这一行得到这个警告[self.dobActionSheet showInView:self.parentViewController.view];..

我尝试在第一个索引处显示Viewcontroller,即embedded in tabbarController。这就是为什么,尝试使用parentViewController.view 而不是self.view 进行演示

注意:我看到了同样的问题here。但找不到答案。

【问题讨论】:

  • 试试 [self.dobActionSheet showInView:self.view];
  • 我做不到。因为这个视图控制器在第一个索引处嵌入在 tabbarcontroller 中。这是正确的方法吗?任何方式都试过这个,但得到了同样的错误.. !!
  • @c0ming 感谢您的链接。我已经尝试过了,但它对我不起作用。

标签: ios datepicker uiactionsheet


【解决方案1】:
actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title"
                                              delegate:self
                                     cancelButtonTitle:nil
                                destructiveButtonTitle:nil
                                     otherButtonTitles:@"Ok"];

使用 @""

代替 nil 值
actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:nil
cancelButtonTitle:@""
destructiveButtonTitle:nil
otherButtonTitles:nil];

【讨论】:

  • 操作表显示标题.. 所以我尝试使用单个空格作为标题。它正在工作。看我的回答..感谢+1你:)
【解决方案2】:

我已经从@Sunny shah 的回答中解决了这个问题。我已经尝试过他的回答,但在操作表上有title。相反,我尝试使用以下代码。(标题名称为单个空格)。

self.dobActionSheet = [[UIActionSheet alloc] initWithTitle:@" " delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil,nil];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-30
    • 2012-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多