第一次攻击时奇怪的崩溃UITextField

问题描述:

我在我的Cocos2d应用程序中有一个文本字段,当我点击它开始输入时,应用程序崩溃。我没有更多的解释,这里是我的代码: .H:第一次攻击时奇怪的崩溃UITextField

@interface myScene : CCLayer <UITextFieldDelegate> { ....... } 
@property (nonatomic, retain, readonly) UITextField *first; 
@property (nonatomic, retain, readonly) UITextField *second; 

.mm:

@implementation myScene 
    @synthesize first, second; 
    ...... 
     first = [[UITextField alloc] initWithFrame:CGRectMake(160.0, 160.0, 200.0, 30.0)]; 
     first.placeholder = @"first"; 
     first.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction suppor 
     first.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard) 
     first.returnKeyType = UIReturnKeyDone; 
     first.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right 
     first.autocapitalizationType = UITextAutocapitalizationTypeNone; 
     CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2); 
     first.transform = transform; 
     first.adjustsFontSizeToFitWidth = YES; 
     first.textColor = [UIColor blackColor]; 
     [first setFont:[UIFont fontWithName:@"Arial" size:14]]; 
     first.backgroundColor = [UIColor clearColor]; 
     first.borderStyle = UITextBorderStyleRoundedRect; 
     first.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed 
     [[[CCDirector sharedDirector] openGLView] addSubview: first]; 


     second = [[UITextField alloc] initWithFrame:CGRectMake(130.0, 160.0, 200.0, 30.0)]; 
     second.placeholder = @"second"; 
     second.returnKeyType = UIReturnKeyDone; 

     second.transform = transform; 
     second.adjustsFontSizeToFitWidth = YES; 
     second.textColor = [UIColor blackColor]; 
     [second setFont:[UIFont fontWithName:@"Arial" size:14]]; 
     second.backgroundColor = [UIColor clearColor]; 
     second.borderStyle = UITextBorderStyleRoundedRect; 
     second.secureTextEntry = YES; 
     second.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed 
     [[[CCDirector sharedDirector] openGLView] addSubview: second]; 

............... 


    - (BOOL)textFieldShouldReturn:(UITextField *)textField 
    { 
     // the user pressed the "Done" button, so dismiss the keyboard 
     [textField resignFirstResponder]; 
     return YES; 
    } 

我上的Xcode 4运行与iOS 4.3和当我点击一个字段我得到EXC_BAD_ACCESS和Xcode中指出我的main.m:

#import <UIKit/UIKit.h> 

int main(int argc, char *argv[]) { 
    NSAutoreleasePool *pool = [NSAutoreleasePool new]; 
    int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate"); 
    [pool release]; 
    return retVal; 
} 

Xcode的指示线:int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");

谢谢。

+0

把你的崩溃日志... – Jhaliya 2011-05-13 19:14:12

+0

Jhaliya是正确的。你还有更多需要解释的东西,那就是你的应用程序崩溃时的确切消息和其他行为。 – 2011-05-13 19:21:55

+0

补充,对不起... – user465166 2011-05-13 19:23:10

我不认为这是在openGL视图中添加文本字段的最佳方式,实际上我不确定它会起作用。你可能需要在UIViewController子类中有你的字段,然后将该类的视图添加到你的openGLView,或者有一个很好的UIViewWrapper,你可以得到here。它可以让你添加UIView元素到你的CCLayer。希望这有助于

+0

谢谢。我使用链接,它的工作原理。 – user465166 2011-05-13 19:59:08

尝试添加NSZombieEnabled在http://www.cocoadev.com/index.pl?NSZombieEnabled

描述应该写更多的东西比instresting“EXC_BAD_ACCESS”消息