2013-10-02 47 views
1

我正在使用操作表來顯示供用戶選擇的數據列表。問題是顯示使用[self.actionSheet showInView:self.view];的操作表正在導致幾個CGContext錯誤。同樣的代碼在iOS中行之有效6.顯示操作表導致CGContext無效上下文錯誤

代碼:

self.actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
              delegate:nil 
            cancelButtonTitle:nil 
           destructiveButtonTitle:nil 
            otherButtonTitles:nil]; 
[self.actionSheet setActionSheetStyle:UIActionSheetStyleBlackOpaque]; 

CGRect tableFrame = CGRectMake(0, 40, 320, 214); 
self.tableView = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStylePlain]; 
self.tableView.dataSource = self; 
self.tableView.delegate = self; 
[self.actionSheet addSubview:self.tableView]; 

UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]]; 
closeButton.momentary = YES; 
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); 
closeButton.tintColor = [UIColor redColor]; 
[closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged]; 
[self.actionSheet addSubview:closeButton]; 

[self.actionSheet showFromView:self.view]; 

[UIView beginAnimations:nil context:nil]; 
[self.actionSheet setBounds:CGRectMake(0, 0, 320, 485)]; 
[UIView commitAnimations]; 

錯誤:

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. 
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. 
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. 
CGContextSetFlatness: 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. 
CGContextAddPath: 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. 
CGContextDrawPath: 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. 
CGContextRestoreGState: 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. 

更新:

到cancelButtonTitle設置爲@ 「」 導致的解決方法這對我的UI問題:

afterbefore

原始代碼來自另一個stackoverflow答案,請參閱https://stackoverflow.com/a/2074451/654870

回答

3

我相信這裏的答案是UIActionSheet不打算以這種方式使用,並因此可能有這些副作用。從Apple ActionSheet documentation,「UIActionSheet不是被設計爲子類,也不應該添加視圖到其層次結構。」

雖然這並沒有給iOS 6帶來問題,但iOS 7中的某些內容已經發生了明顯變化,我更傾向於採用另一種方式,而不是嘗試去做與文檔相矛盾的事情。請注意,解決方法可能是爲cancelButtonTitle傳遞@「」而不是零,但這會導致其他UI問題,並且可能不會被Apple批准。

替代方案:

  1. 創建自己的看法和模態呈現 - 我做了一個簡單example project顯示做到這一點的方法之一。
  2. https://github.com/gpambrozio/BlockAlertsAnd-ActionSheets(適用於iOS 7還沒有更新)
+0

確實,我們試圖將行動表用作窮人的iPhone彈出窗口。由於@ kyle的回答,我們做了一些重構,現在我們只是將內容呈現在模態UINavigationController中。 –

2

凱爾,還有什麼其他的UI問題,你必須使用之後@ 「」?

當我使用下面的代碼後,它對我來說工作正常。我不使用tableview,但我使用pickerview作爲子視圖。

self.startSheet=[[UIActionSheet alloc]initWithTitle:nil 
              delegate:nil 
            cancelButtonTitle:@"" 
          destructiveButtonTitle:nil 
            otherButtonTitles:nil]; 
+1

查看我的更新中的屏幕截圖。 –

0

這裏是一個答案我介紹了一個類似的question行之有效

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

但是這會搞亂圖形/在你的動作片的頂部繪製,所以如果你不已經有一個添加背景只需添加此代碼即可爲您提供默認操作工作表外觀。

UIView *background = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 
background.backgroundColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1]; 
[self.actionSheet addSubview:background]; 

然後添加任何你想要的自定義操作表。

+0

不幸的是沒有工作 –

+0

@BraveS究竟發生了什麼? – horsejockey

+0

背景在ios7中仍然是透明的 –

相關問題