我用 Xcode 4.5.1 更新了 iOS 6.0 SDK,在我的应用程序中使用多字节键盘(例如日文键盘)编辑 UITextField 时出现了无效的上下文错误 0x0。以下是错误:
Oct 9 21:46:44 example.com Example[2303] <Error>: CGContextSaveGState: invalid context 0x0
Oct 9 21:46:44 example.com Example[2303] <Error>: CGContextDrawLinearGradient: invalid context 0x0
Oct 9 21:46:44 example.com Example[2303] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
Oct 9 21:46:44 example.com Example[2303] <Error>: CGContextFillRects: invalid context 0x0
Oct 9 21:46:44 example.com Example[2303] <Error>: CGContextFillRects: invalid context 0x0
Oct 9 21:46:44 example.com Example[2303] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
Oct 9 21:46:44 example.com Example[2303] <Error>: CGContextFillRects: invalid context 0x0
Oct 9 21:46:44 example.com Example[2303] <Error>: CGContextSaveGState: invalid context 0x0
Oct 9 21:46:44 example.com Example[2303] <Error>: CGContextDrawLinearGradient: invalid context 0x0
Oct 9 21:46:44 example.com Example[2303] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
Oct 9 21:46:44 example.com Example[2303] <Error>: CGContextFillRects: invalid context 0x0
Oct 9 21:46:44 example.com Example[2303] <Error>: CGContextFillRects: invalid context 0x0
Oct 9 21:46:44 example.com Example[2303] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
Oct 9 21:46:44 example.com Example[2303] <Error>: CGContextFillRects: invalid context 0x0
我试图创建新项目,但我遇到了这些错误。以下是新项目代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UITextField *foo = [[UITextField alloc] initWithFrame:CGRectMake(30, 30, 200, 50)];
[self.window addSubview:foo];
return YES;
}
如果您使用美式键盘进行编辑,则不会出现错误。你知道如何避免这个问题吗?