将xib出口加载到另一个视图控制器

时间:2015-11-18 03:18:50

标签: ios objective-c

我有一个名为BookingMain的Viewcontoller,在运行时它会查询名为BookingForm的xib。 在BookingForm中有出口fullName, Email, Telephone

我试图从我的BookingMain访问这些商店。

所以我所做的是@implementation BookingMain我添加了BookingForm *book;  然后尝试以这种方式访问​​那些BookingForm

NSString *Name;
book.fullName.text = Name;

//book.fullName.text : this is always null

但它给了我空值。

我是iOS新手,无法弄清楚。

更新:

.H file

@interface BookingForm : UIView

@property (strong, nonatomic) IBOutlet UIView *view;


@property (weak, nonatomic) IBOutlet UITextField *fullName;
@property (weak, nonatomic) IBOutlet UITextField *email;
@property (weak, nonatomic) IBOutlet UITextField *phone;

.m File

#import "BookingForm.h"

@implementation BookingUserDetails

-(id)initWithCoder:(NSCoder *)aDecoder{

    self = [super initWithCoder:aDecoder];

    if (self) {

        NSString *xib = @"BookingForm";

        [[NSBundle mainBundle] loadNibNamed:xib owner:self options:nil];

        [self addSubview:self.view];
    }

    return self;

}

@end

1 个答案:

答案 0 :(得分:0)

要检查的几件事情:

  • 在创建BookingForm时,使用[BookingForm alloc] init];您正在调用init方法。所以添加一个init方法并复制你当前在initWithCoder方法中拥有的代码。

  • 在下面的代码中,您只声明名为Name的变量。此时它仍为零,因为名称尚未分配或初始化。当你将它分配给book.fullName.text时,这也将是零。

    NSString *Name;
    book.fullName.text = Name;
    //book.fullName.text : this is always null