2

我在下面有以下代码,我无法弄清楚为什么textFieldShouldReturn没有调用该方法。当我使用 IB 创建到委托的连接时,它可以工作,但是当以编程方式完成时,日志语句不会显示。我在这里做错了什么?

其次,在 中textFieldShouldReturn,有的例子返回YES,有的返回NO。ios 文档指定返回YES将提供默认实现。有人可以更详细地解释一下吗?

//.h文件

@interface GoSocietyLoginController : UIViewController <UITextFieldDelegate> {    
}
- (IBAction)textFieldDoneEditing:(id)sender;
- (BOOL)textFieldShouldReturn:(UITextField *)textField;

@end

//.m文件

@interface GoSocietyLoginController ()

@property (nonatomic,retain) IBOutlet UITextField   *login;
@property (nonatomic,retain) IBOutlet UITextField   *password;

@end


@implementation GoSocietyLoginController

@synthesize login;
@synthesize password;

    - (void)viewDidLoad
    {    
        [super viewDidLoad];
        [login setDelegate:self];
        [password setDelegate:self];
    }

    - (BOOL)textFieldShouldReturn:(UITextField *)textField {
        NSLog(@"Hello World");

        if ([textField isEqual:login]) {
            [password becomeFirstResponder];
        }

        return NO;
    }
4

1 回答 1

0

从您发布的代码来看,在我看来您没有在标题中声明网点:

IBOutlet UITextField *login;
IBOutlet UITextField *password;

请务必声明它们并在 IB 中设置连接。

于 2011-07-07T22:34:11.077 回答