因此,当用户想要恢复密码时,他们会点按一个按钮,子视图会显示UITextField
和UIButton
。用户输入电子邮件后,我希望UIButton
发送电子邮件。我错过了UITextField
的推荐。这是我的代码:
- (IBAction)recoverPassword:(id)sender {
CGRect frame = CGRectMake(12, 51, 298, 497);
UIView *infoView = [[UIView alloc] initWithFrame:frame];
infoView.opaque = NO;
infoView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8f];
infoView.userInteractionEnabled = YES;
infoView.tag = 01;
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(8, 200, 280, 30)];
textField.textAlignment = NSTextAlignmentLeft;
textField.textColor = [UIColor blackColor];
UIButton *getPassword = [[UIButton alloc] initWithFrame:CGRectMake(8, 265, 280, 36)];
getPassword.backgroundColor = [UIColor blackColor];
[getPassword addTarget:self
action:@selector(getUserPassword:)
forControlEvents:UIControlEventTouchUpInside];
[infoView addSubview:textField];
[infoView addSubview:getPassword];
[self.view addSubview:infoView];
}
- (void)getUserPassword:(UITapGestureRecognizer *)sendPassword {
[PFUser requestPasswordResetForEmailInBackground:**Missing Part**];
[[self.view viewWithTag:01] removeFromSuperview];
NSLog(@"Dissmissed Info SubView");
}
答案 0 :(得分:0)
看起来您只在本地范围(方法范围内)创建子视图(UITextField,UIButton等),因此同一类的其他方法无法访问它们。
尝试为您拥有这些方法的类创建一个ivar,并将值分配给ivar,这样就可以在-getUserPassword:
方法中访问相同的变量。
P.S。同样的方法,但应用于infoView
,将无需通过viewWithTag
访问它,因为您可以直接访问它。