我在创建新视图时遇到问题,我有一个注册视图,上面有一个 UITextField 和一个 UIButton。
我从另一个视图中调用这个视图
//其他视图.m
- (void)viewDidLoad
{
[super viewDidLoad];
RegistrationAlertViewController *regreg = [[RegistrationAlertViewController alloc] init];
[self.view addSubview:regreg.view];
}
然后我像这样创建我的 regregview
//regregView.h
#import <UIKit/UIKit.h>
@interface RegistrationAlertViewController : UIViewController <UITextFieldDelegate> {
// textfields for registration
IBOutlet UITextField *registrationTextFieldA;
}
// textfields for registration
@property (strong, nonatomic) IBOutlet UITextField *registrationTextFieldA;
@end
//regregView.m
#import "RegistrationAlertViewController.h"
@interface RegistrationAlertViewController ()
@end
@implementation RegistrationAlertViewController
@synthesize registrationTextFieldA;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
registrationTextFieldA = [[UITextField alloc] init];
registrationTextFieldA.delegate = self;
[registrationTextFieldA becomeFirstResponder];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if([textField.text length] > 4)
{
//Get next TextField... A simple way to do this:
// UITextField *newTextField = [textField.superview viewWithTag:(textField.tag+1)];
// [newTextField becomeFirstResponder];
return NO;
//remember to set the tags in order
}
return YES; //you probably want to review this...
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if((textField.text.length + string.length) > 4)
{
//Get next TextField... A simple way to do this:
// UITextField *newTextField = [textField.superview viewWithTag:(textField.tag+1)];
// [newTextField becomeFirstResponder];
//remember to set the tags in order
}
return YES; //you probably want to review this...
}
@end
我的 regregView.m 中有两个代表
- textFieldShouldBeginEditing
- shouldChangeCharactersInRange
由于某些奇怪的原因textFieldShouldBeginEditing在视图首次加载时输入,但是当我开始将字符输入到registrationTextFieldA shouldChangeCharactersInRange时,由于某些奇怪的原因永远不会输入。
任何帮助找出为什么我的代表不能正常工作的帮助将不胜感激。