Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'invalid context error 0x0', when editing uitextfield using mult byte keyboard with iOS 6.0

I updated iOS 6.0 SDK with Xcode 4.5.1, and I had invalid context error 0x0 when editing UITextField with mult byte keyboard(e.g. japanese keyboard) in my application. The following is error:

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

I tried to create new project and I had these errors. The following is new project code:

- (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;
}

if you edit with US keyboard, you will not have errors. Do you know how to avoid this problem?

like image 722
terut Avatar asked Oct 09 '12 13:10

terut


1 Answers

This error can be traced to double clicking on a uitextfield that is empty. It is a bug in iOS. Init your textfield to " " and the error will disappear.

like image 53
G M Avatar answered Dec 07 '22 18:12

G M