iphone - 在 UIActionSheet 中添加 UIPickerView 时,iOS 7 上出现无效上下文错误?

标签 iphone ios ios7 uipickerview uiactionsheet

我在 UIActionSheet 中有一个 UIPickerView,并按照许多其他人在 SO 中建议的方式完成了该操作:

Add UIPickerView & a Button in Action sheet - How?

how to add UIPickerView in UIActionSheet

直到现在,当我在 iOS 7 上测试我的应用程序时,这些解决方案都运行良好。它仍然可以运行,但我在 Xcode 运行时收到了很多“无效上下文 0x0”警告。

The errors are coming with a nice message too:

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.

可能是 Apple 最终想停止这种解决方案,还是我们可以解决或解决这个问题?

最佳答案

此“无效上下文 0x0”警告的解决方法是使用非 nil 标题初始化 UIActionSheet(非 nil 按钮也可以解决错误,但会导致视觉伪像)。

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

然后您需要调整操作表的框架以使其在 iOS7 和以前的版本中正确定位(确保在 showInView 方法之后执行此操作)。

CGRect newFrame = actionSheet.frame;
newFrame = self.view.bounds.size.height - myCustomPicker.frame.size.height;
newFrame = myCustomPicker.frame.size.height;
actionSheet.frame = newFrame;

关于iphone - 在 UIActionSheet 中添加 UIPickerView 时,iOS 7 上出现无效上下文错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19011170/

相关文章:

iphone - NSRegularExpression 帮助

iphone,在不执行提取的情况下获取对象计数?

iphone - #import 和@class 的问题导致从错误中引用 _OBJC_CLASS_

ios - 在 Xcode 11 中分组时无法创建类的实例

ios - 核心文本中的垂直文本对齐

ios - 从 ios 7 的后台更新位置?

iphone - 在第二部 iPhone 上测试

ios - 如何检测 child Sprite 的触摸

ios - 自定义 iOS 7 状态栏文字颜色

ios - 如何更改 iOS 7 中选定的标签栏项目颜色?