Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid context 0x0 on UITextField (Xcode 5)

I am using a UITextField in my app. I am using [texfield becomeFirstResponder]. This works just fine and loads the keyboard when the view is loaded. However, this error comes up when I click on the UITextField again after it has been brought up. I don't understand exactly why, but here is the output I am getting:

CGContextSetFillColorWithColor: invalid context 0x0.
CGContextSetStrokeColorWithColor: invalid context 0x0. 
CGContextSaveGState: invalid context 0x0. 
CGContextSetFlatness: invalid context 0x0. 
CGContextAddPath: invalid context 0x0. 
CGContextDrawPath: invalid context 0x0. 
CGContextRestoreGState: invalid context 0x0. 
CGContextSaveGState: invalid context 0x0. 
CGContextSetFlatness: invalid context 0x0. 
CGContextAddPath: invalid context 0x0.
CGContextDrawPath: invalid context 0x0. 
CGContextRestoreGState: invalid context 0x0.

Here is my code:

// ViewController.h
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *textField;

@end


// ViewController.m
@synthesize textField;

- (void)viewDidLoad
{
    [textField becomeFirstResponder];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
like image 593
Zack Avatar asked Nov 01 '22 12:11

Zack


1 Answers

I believe you've found an iOS bug (or at least a simulator bug). You can reproduce it even more simply:

  • New Project (Single View)
  • Drag UITextField onto Storyboard
  • Run
  • Click on UITextField.
  • Click off of UITextField
  • Click on UITextField
  • (In some cases, you need to click off of UITextField again)
  • Observe errors

I recommend opening a radar.

like image 78
Rob Napier Avatar answered Nov 08 '22 07:11

Rob Napier