1.) 将您的嵌入转场命名为“TextFields”
2.) 如果你还没有,子类化UITableViewController
并将表视图控制器设置为故事板中的此类。我们就这样称呼它吧TextFieldsTableViewController
.
3.) 再次,如果您还没有添加,请添加IBOutlet
s 将您的文本字段放入TextFieldsTableViewController
的公共接口:
@property (weak, nonatomic) IBOutlet UITextField *firstNameField;
@property (weak, nonatomic) IBOutlet UITextField *usernameField;
@property (weak, nonatomic) IBOutlet UITextField *emailField;
@property (weak, nonatomic) IBOutlet UITextField *passwordField;
4.) 将文本字段的属性添加到LoginViewController
的公共接口(请注意,与上面不同,这些并不弱(它们也不是IBOutlet
s,但这并不重要)):
@property (nonatomic) UITextField *firstNameField;
@property (nonatomic) UITextField *usernameField;
@property (nonatomic) UITextField *emailField;
@property (nonatomic) UITextField *passwordField;
5.) In LoginViewController
's prepareForSegue:sender:
方法,映射TextFieldsTableViewController
的文本字段self
强制立即加载表视图控制器的视图后的文本字段:
if ([segue.identifier isEqualToString:@"TextFields"]) {
TextFieldsTableViewController *textFieldsVC = segue.destinationViewController;
// IMPORTANT: This forces the view to load and the outlets to get set.
// If you don't do this, textFieldsVC's IBOutlets will all be nil at this point.
// This is slightly inelegant in my opinion, but it works. A better solution might
// be to set the text fields in TextFieldsTableViewController's viewDidLoad method.
[textFieldsVC view];
self.firstNameField = textFieldsVC.firstNameField;
self.usernameField = textFieldsVC.usernameField;
self.emailField = textFieldsVC.emailField;
self.passwordField = textFieldsVC.passwordField;
}
6.) 您现在应该能够访问中的文本字段LoginViewController
's viewDidLoad
method.