This is how I use a XIB view controllers view as a subview in the MainViewController:
UIViewController *nameController = [[NameSubViewController alloc] initWithNibName:@"NameSubViewController" bundle:nil];
nameSubView = [nameController view];
[self.view addSubview:nameSubView];
The nameController view contains a UITextField property. Can I somehow access this property from MainViewController?
EDIT:
If I create a property for the textField in the View Controller too, I’m still not able to get it in MainViewController. Think it’s because of the UIView subclassed causing problems?
NameSubViewController.h:
#import <UIKit/UIKit.h>
@interface NameSubViewController : UIViewController
@property (nonatomic, strong) IBOutlet UITextField *textField;
@end
NameSubView.h:
#import <UIKit/UIKit.h>
@interface NameSubView : UIView
@property (nonatomic, strong) IBOutlet UITextField *textField;
- (IBAction)textFieldReturn:(id)sender;
@end
Connections in IB for NameSubViewController:
Connections, NameSubViewController
Connections in IB for NameSubView:
Did you create an outlet for the textfield in your nameController? Do that, and then you can retrieve the value using
In the nib file, click on the file’s owner icon (on the left of the nib), and set it’s class to your UIView’s subclass using the inspector on the right.