UIActionSheet showInView发出警告:无效的上下文0x0

时间:2014-02-28 05:53:53

标签: ios datepicker uiactionsheet

我正试图在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。但是找不到答案。

2 个答案:

答案 0 :(得分:4)

actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title"
                                              delegate:self
                                     cancelButtonTitle:nil
                                destructiveButtonTitle:nil
                                     otherButtonTitles:@"Ok"];

而不是零值,请使用@&#34;&#34;

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

答案 1 :(得分:0)

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

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