development

UISearchBar CGContext 오류

big-blog 2021. 1. 8. 22:45
반응형

UISearchBar CGContext 오류


뷰 안에 UISearchBar가 있습니다. 키보드가 나타나면 탭할 때마다-

-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar

다음을 콘솔로 보냅니다.

<오류> : CGContextSetStrokeColorWithColor: 잘못된 컨텍스트 0x0입니다. 이것은 심각한 오류입니다. 이 응용 프로그램 또는이 응용 프로그램이 사용하는 라이브러리는 잘못된 컨텍스트를 사용하므로 시스템 안정성과 안정성이 전반적으로 저하됩니다. 이 알림은 예의입니다.이 문제를 수정하세요. 향후 업데이트에서 치명적인 오류가 될 것입니다.

같은 오류를 반복합니다. 정확히 무엇이 문제 일 수 있는지 궁금합니다.

NULL 컨텍스트 가 있다고 생각 하지만 UISearchBar와 관련이 있습니까? tnx.


Apple이 작업중인 알려진 문제입니다. 다음 베타 릴리스에서 수정되어야합니다.

여기를보세요 : 십진수 오류가있는 Xcode 숫자 패드

편집 : 텍스트 필드에 문제가있는 사람들은이 문제를 해결할 수 있습니다.

Apple Developer Forums bye Popeye7-모든 크레딧은 그에게

이 문제에 대한 해결책을 찾았습니다! 지금은 고장난 앱이 3 개 있습니다. 그래서 나에게 ... 이것은 좋은 발견입니다. StackOverflow에서 해결책을 찾았습니다 ... 유사한 질문에 대한 두 가지 답변을 결합했습니다.

제 경우에는 사용자가 barButtonItem을 탭하면 "경고"또는 대화 상자가 나타납니다.

UIAlertView가 할당되는 방식에 큰 차이가 있습니다. "NEW WAY"에는 textField가 표시되고 키보드가 표시됩니다.

이제 textField를보고 텍스트를 입력 할 수 있으며 예상대로 작동합니다. "initWithFrame"을 다시 추가해도 textField 배치에 영향을주지 않습니다.

옛날 방식 ....

- (IBAction)addEntryTapped:(id)sender

{

    [_editorTextView resignFirstResponder];
    [self saveTextChanges];
    [self dismissPopovers];

    _prompt = [[UIAlertView alloc] initWithTitle:@"New Entry Title..."
                                         message:@"\n\n\n" // IMPORTANT
                                        delegate:self
                               cancelButtonTitle:@"Cancel"
                               otherButtonTitles:@"OK", nil];

    _textField = [[UITextField alloc] initWithFrame:CGRectMake(17.0, 55.0, 250.0, 25.0)];

    [_textField setBackgroundColor:[UIColor whiteColor]];
    [_textField setPlaceholder:@"New Entry Title"];

    _textField.borderStyle = UITextBorderStyleRoundedRect;
    _textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
    _textField.autocorrectionType = UITextAutocorrectionTypeNo;

    [_prompt addSubview:_textField];
    [_prompt show];

    // set cursor and show 
    [_textField becomeFirstResponder];
}

새로운 길...

- (IBAction) addEntryTapped:(id)sender
{
    [_editorTextView resignFirstResponder];
    [self saveTextChanges];
    [self dismissPopovers];

    _prompt = [[UIAlertView alloc] init];
    _prompt.alertViewStyle = UIAlertViewStylePlainTextInput;

    UITextField *text = [_prompt textFieldAtIndex:0];
    _textField = text;

    [_prompt setDelegate:self];
    [_prompt setTitle:@"New Entry Title..."];
    [_prompt setMessage:@""];
    [_prompt addButtonWithTitle:@"Cancel"];
    [_prompt addButtonWithTitle:@"OK"];
    [_textField setPlaceholder:@"New Entry Title"];

    _textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
    _textField.autocorrectionType = UITextAutocorrectionTypeNo;

    [_prompt show];

    // set cursor and show keyboard
    [_textField becomeFirstResponder];
}  

Message was edited by Popeye7 on 9/25/13 at 12:25 PM

Message was edited by Popeye7 on 9/25/13 at 12:33 PM


This went away for me after deleting the iOS Simulator preferences from ~/Library/Preferences.

Go to ~/Library/Preferences Drop "com.apple.iphonesimulator.plist" to the trash.

Stateful


It appears that the UISearchBar's AutoLayout constraints that are set in the .xib file are causing this problem. If there are any redundant or conflicting constraints that weren't caught by the compiler it can cause a drawing error and throw these errors.

  1. Go to the .xib file that has the UISearchBar
  2. Click on the UISearchBar and go to the Size Inspector (looks like a ruler, usually on the right side with the control's properties)
  3. One by one, click on each constraint and watch to see where they are - no two constraints should be measuring the same property. For example, on mine, I had one constraint measuring from the top of the control to the top of the view, and another constraint measuring from the bottom of the control to the top of the view.
  4. Remove any offending constraints, build, and run! If that doesn't work, you may want to check the constraints on the surrounding controls.

This "missing context" thing seems to be a iOS 7 bug and it seems to occur only for empty textfields. I am using a lightweight workaround in my projects until this issue got fixed by Apple (so probably never ;)).

// or wherever
- (void)viewDidLoad
{
     if([textfield.text isEqualToString:@""] || textfield.text == nil)
     {
           textfield.text = @" ";
     }
     ...
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)theTextField
{
     [[NSNotificationCenter defaultCenter] addObserver:self
                                              selector:@selector(keyboardDidShow:)
                                                  name:UIKeyboardDidShowNotification
                                                object:nil];
     return YES;
}

- (void)keyboardDidShow:(NSNotification *)notification
{
    if([textField.text isEqualToString:@" "])
    {
         textField.text = @"";
    }
}

...that did it for me.

EDIT: You need to implement UITextFieldDelegate, of course. EDIT 2: Unfortunately, it didn't work exactly as I expected. The error is gone, but the whitespace-character is not removed most of the time...Anyone got a solution for this? EDIT 3: I am giving up on that issue. This way does not cover up all use cases of UITextField and it decreases the UX.

ReferenceURL : https://stackoverflow.com/questions/17777928/uisearchbar-cgcontext-error

반응형