首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >UISearchBar CGContext错误

UISearchBar CGContext错误
EN

Stack Overflow用户
提问于 2013-07-22 07:15:53
回答 4查看 19.9K关注 0票数 55

我在一个视图里有一个UISearchBar,每当我点击它,在键盘弹出之后-

-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar之后

它将此消息发送到控制台:

CGContextSetStrokeColorWithColor:无效的上下文0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体降级。此通知是出于礼貌:请解决此问题。在即将到来的更新中,它将成为一个致命错误。

它重复相同的错误。我想知道到底是什么问题?

我相信存在一个空的上下文,但它与UISearchBar有什么关系呢?tnx。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-07-23 20:33:38

这是苹果正在努力解决的一个已知问题。应该会在下一个beta版本中修复。

看看这里:Xcode Number pad with decimal error

编辑:对于那些对文本字段有问题的人来说,这可能会帮助你解决这个问题:

From Apple Developer Forums bye Popeye7 - So all credits to him

我已经找到了解决这个问题的方法!我有三个应用程序,现在这个坏掉了,所以,对我来说…这是一个很好的发现。在StackOverflow上找到了解决方案...组合了两个类似问题的答案。

在我的例子中,用户点击一个barButtonItem,就会出现一个“警告”或对话框。

我发现最大的区别在于UIAlertView是如何分配的。“新方法”会显示textField,并按需要调出键盘。

我现在可以看到textField,输入文本,它的工作方式与我期望的一样。重新添加"initWithFrame“不会影响textField的放置。

老方法..。

代码语言:javascript
复制
- (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];
}

的新方式...

代码语言:javascript
复制
- (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];
}  

Popeye7在13年9月25日下午12:25编辑了

消息

消息在时间13年9月25日12:33由Popeye7编辑

票数 22
EN

Stack Overflow用户

发布于 2013-09-26 00:42:36

在从~/库/首选项中删除iOS模拟器首选项后,这个问题就消失了。

转到~/库/首选项将"com.apple.iphonesimulator.plist“拖到垃圾桶中。

有状态

票数 16
EN

Stack Overflow用户

发布于 2013-09-21 13:18:50

似乎是在.xib文件中设置的UISearchBar的AutoLayout约束导致了这个问题。如果有任何多余或冲突的约束没有被编译器捕获,就会导致绘制错误并抛出这些错误。

  1. 转到在UISearchBar上有UISearchBar
  2. Click的.xib文件,然后转到大小检查器(看起来像一把标尺,通常在右侧,控件的properties)
  3. One为1),单击每个约束并查看它们在哪里-不应该有两个约束测量相同的属性。例如,在我的示例中,我有一个从控件顶部到视图顶部的约束,以及另一个从控件底部到视图顶部的约束。
  4. 删除任何有问题的约束,构建并运行!如果这不起作用,您可能需要检查周围控件的约束。
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17777928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档