在我的UIViewController中,我有2个文本字段。一个叫passwordtextfield,另一个叫retype。而不是让人们实际重新键入他们的密码,我希望它自动填写它。这可能吗?我尝试了一些不断崩溃的东西。
[_passwordtextfield addTarget:self action:@selector(updateTextField:) forControlEvents:UIControlEventEditingChanged];
- (void)updateTextField:(id)sender{
UITextField *retype = ((UITextField *)_passwordtextfield).text;
}
答案 0 :(得分:1)
无需投射文字字段。您可以指定文本字段的直接值。所以
写下这一行
retypetextfield.text = _passwordtextfield.text;
而不是
UITextField *retype = ((UITextField *)_passwordtextfield).text;
答案 1 :(得分:0)
我不知道您为什么要这样做,如评论中所述,但回答问题...看起来您正在UITextField
中创建一个新的updateTextField
而不是设置存在的文本。看起来应该是这样的:
- (void)updateTextField:(id)sender{
retypeFied.Text = _passwordtextfield.text;
}
将指定指针的任何内容替换为retypeField
的第二个字段。