我发现了很多如何使用 chlidViewController 的方法。但我找不到如何从 childViewController 更改和设置 uitextfield 和 uiswitch 的值。
ChildViewController.h:
@protocol VVInformationTableViewControllerDelegate;
@interface VVInformationTableViewController : UITableViewController
@property (weak, nonatomic) id<VVInformationTableViewControllerDelegate> delegate;
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@property (weak, nonatomic) IBOutlet UITextField *surnameTextField;
@property (weak, nonatomic) IBOutlet UITextField *emailTextField;
@property (weak, nonatomic) IBOutlet UITextField *locationTextField;
@property (weak, nonatomic) IBOutlet UITextField *headlineTextField;
@property (weak, nonatomic) IBOutlet UITextField *positionTextField;
@property (weak, nonatomic) IBOutlet UITextField *companyTextField;
@property (weak, nonatomic) IBOutlet UISwitch *messagesEnable;
@end
ParentViewControler.m:
- (void)viewDidLoad
{
self.currentAttendee = [VVAPIClient sharedClient].currentUser;
NSParameterAssert(self.currentAttendee);
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES];
self.infoTableController = [[VVInformationTableViewController alloc] initWithNibName:@"InformationTableViewController" bundle:nil];
[self addChildViewController:self.infoTableController];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.infoTableController.nameTextField.text = self.currentAttendee.firstName?:@"";
self.infoTableController.surnameTextField.text = self.currentAttendee.lastName?:@"";
self.infoTableController.emailTextField.text = self.currentAttendee.email?:@"";
self.infoTableController.locationTextField.text = self.currentAttendee.location?:@"";
self.infoTableController.headlineTextField.text = self.currentAttendee.headline?:@"";
self.infoTableController.positionTextField.text = self.currentAttendee.position?:@"";
self.infoTableController.companyTextField.text = self.currentAttendee.company?:@"";
}
-(void)viewDidLayoutSubviews{
self.infoTableController.messagesEnable.on = NO;
self.infoTableController.nameTextField.tag = 0;
self.infoTableController.surnameTextField.tag = 1;
self.infoTableController.emailTextField.tag = 2;
self.infoTableController.locationTextField.tag = 3;
self.infoTableController.headlineTextField.tag = 5;
self.infoTableController.positionTextField.tag = 6;
self.infoTableController.companyTextField.tag = 7;
}
感谢帮助。