我的Cocos2d应用程序中有一个文本字段,当我点击它开始输入时,应用程序就崩溃了。我没有太多要解释的,这是我的代码: .H:
@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;
}
我正在使用iOS 4.3在Xcode 4上运行,当我点击其中一个字段时,我得到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 :(得分:1)
我不认为这是在openGL视图中添加文本字段的最佳方式,事实上我不确定它是否有效。您可能需要在UIViewController子类中包含字段,然后将该类的视图添加到openGLView
,或者有一个好的UIViewWrapper可以获得here。它允许您将UIView元素添加到CCLayer。希望这有帮助
答案 1 :(得分:0)
尝试按照http://www.cocoadev.com/index.pl?NSZombieEnabled
中的说明添加NSZombieEnabled它应该写一些比“EXC_BAD_ACCESS”消息
更令人感动的东西