显示操作表会导致CGContext无效上下文错误 [英] Showing actionsheet causes CGContext invalid context errors
问题描述
我正在使用操作表显示数据列表,以供用户选择。问题是使用 [self.actionSheet showInView:self.view];
显示操作表会导致多个CGContext错误。相同的代码在iOS 6中效果很好。
I'm using actionsheet to display lists of data for the user to choose from. The problem is that showing the actionsheet using [self.actionSheet showInView:self.view];
is causing several CGContext errors. The same code worked well in iOS 6.
代码:
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问题:
The workaround to set cancelButtonTitle to @"" results in this UI problem for me:
原始代码来自另一个stackoverflow答案,请参见 https://stackoverflow.com/a/2074451/654870。
The original code came from another stackoverflow answer, see https://stackoverflow.com/a/2074451/654870.
推荐答案
我相信这里的答案是UIActionSheet不能以这种方式使用,因此可能这些副作用。从 Apple ActionSheet文档, UIActionSheet并非旨在进行子类化,也不应在其层次结构中添加视图。
I believe the answer here is that UIActionSheet is not intended to be used this way, and as a result may have side effects like these. From the Apple ActionSheet documentation, "UIActionSheet is not designed to be subclassed, nor should you add views to its hierarchy."
虽然这并没有给我造成iOS 6的问题,但iOS 7却发生了一些明显的变化,我更愿意走另一条路而不是尝试与文档矛盾的东西。请注意,一种解决方法可能是为cancelButtonTitle传递@而不是nil,但这会导致其他UI问题,并且可能不会被Apple批准。
While this didn't cause problems for me in iOS 6, something has clearly changed in iOS 7 and I am more in favor of going down another route than trying to do something that contradicts the docs. Note that a workaround may be to pass @"" for the cancelButtonTitle rather than nil, but this causes other UI problems and may not be approved by Apple.
替代解决方案:
- 创建自己的视图并以模态显示-我做了一个简单的示例项目显示了执行此操作的一种方法。
- https://github.com/gpambrozio/BlockAlertsAnd-ActionSheets (iOS 7尚未更新)
- Create your own view and present it modally - I made a simple example project showing one way to do this.
- https://github.com/gpambrozio/BlockAlertsAnd-ActionSheets (no update for iOS 7 yet)
这篇关于显示操作表会导致CGContext无效上下文错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!