У меня есть текстовое поле в приложении 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;
}
Я работаю на 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");
Спасибо.