簡體   English   中英

將xib插座加載到另一個視圖控制器

[英]load xib outlets to another view controller

我有一個名為BookingMain ,在運行時它將子視圖名為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

這里有幾件事要檢查:

  • 在創建BookingForm時,使用[BookingForm alloc] init]; 您正在調用init方法。 因此,添加一個init方法並復制您當前在initWithCoder方法中擁有的代碼。

  • 在下面的代碼中,您只是聲明一個名為Name的變量。 此時,由於尚未分配或初始化名稱,因此它仍然為零。 當您將其分配給book.fullName.text時,它也將為零。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM