1

我在我的 cocos2d-x 项目中添加了 UITextField。但是当输入时,应用程序有时会崩溃。请给我一些帮助,谢谢。这是我的代码

   m_textField = [[UITextField alloc] initWithFrame:CGRectMake(TEXT_FIELD_POSX, TEXT_FIELD_POSY, TEXT_FIELD_WIDTH, TEXT_FILED_HEIGHT)];
    m_textField.tag = CHAT_TEXT_TAG;
    m_textField.delegate = (AppController *)clientApp.delegate;
    [m_textField setBackgroundColor:[UIColor clearColor]];
    [m_textField setTextColor:[UIColor blackColor]];
    [m_textField setFont:[UIFont fontWithName:@"Helvetica" size:14]];
    m_textField.returnKeyType = UIReturnKeySend;
    m_textField.enablesReturnKeyAutomatically = YES;

    [[EAGLView sharedEGLView] addSubview:m_textField];

和崩溃线程`0

CoreGraphics 0x31e09fcc CGFontStrikeRelease + 71
1   
CoreGraphics 0x31e09f0b CGFontCacheUnlockStrike + 230
2   
CoreGraphics 0x31e09a89 CGGlyphLockUnlock + 52
3   
libRIP.A.dylib 0x34604acd ripc_DrawGlyphs + 1888
4   
CoreGraphics 0x31e05361 CGContextDelegateDrawGlyphs + 44
5   
CoreGraphics 0x31ee530d draw_glyphs + 396
6   
CoreGraphics 0x31e05109 CGContextShowGlyphsWithAdvances + 380
7   
WebCore 0x3664552b _ZN7WebCoreL22showGlyphsWithAdvancesERKNS_10FloatPointEPKNS_14SimpleFontDataEP9CGContextPKtPK6CGSizem + 1918
8   
WebCore 0x36644c8f _ZNK7WebCore4Font10drawGlyphsEPNS_15GraphicsContextEPKNS_14SimpleFontDataERKNS_11GlyphBufferEiiRKNS_10FloatPointEb + 1078
9   
WebCore 0x36644525 _ZNK7WebCore4Font14drawSimpleTextEPNS_15GraphicsContextERKNS_7TextRunERKNS_10FloatPointEii + 348
10  
WebCore 0x366443a3 _ZNK7WebCore4Font8drawTextEPNS_15GraphicsContextERKNS_7TextRunERKNS_10FloatPointEii + 134
11  
WebKit 0x34fd86ef _ZL11drawAtPointPKtiRKN7WebCore10FloatPointERKNS1_4FontEPNS1_15GraphicsContextEbPNS1_10BidiStatusEi + 210
12  
WebKit 0x34fda56b -[NSString(WebStringDrawing) __web_drawInRect:withFont:ellipsis:alignment:letterSpacing:lineSpacing:includeEmoji:truncationRect:measureOnly:renderedStringOut:drawUnderline:] + 3690
13  
WebKit 0x34f52187 -[NSString(WebStringDrawing) __web_drawInRect:withFont:ellipsis:alignment:letterSpacing:lineSpacing:includeEmoji:truncationRect:measureOnly:renderedStringOut:] + 114`
4

1 回答 1

0

您应该像这样实现您的委托方法:

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    cocos2d::CCEGLView* pglview = cocos2d::CCDirector::sharedDirector()->getOpenGLView();
    if(pglview)
    {
        pglview->setIMEKeyboardState(false);
    }
    return YES;
}

希望它会有所帮助:)。

于 2012-12-05T02:28:02.100 回答