1

UILableのxibファイルクラスにプログラムで作成しawakeFromNib、ラベルの高さを取得しようとしていmainViewController.mます. を使用して xib ファイルを読み込もうとしましたNSBundleが、うまくいきませんでした。ロードする別の方法はありますか?awakFromNib電話する必要がありますviewDidLoad

これが私のコードです:

- (void)awakeFromNib
{
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 200)];
    [self.label setText:@"This is a label"];
    [self.myView addSubview:self.label];

    NSLog(@"%f", self.label.frame.size.height);  // Results: 200.0000
}

mainViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [[[NSBundle mainBundle] loadNibNamed:@"customCell" owner:self options:nil]objectAtIndex:0];
    customCell *cellVC = [[cutsomCell alloc] init];

    NSLog(@"%f", cellVC.label.frame.size.height); // Results: 0.0000
}

ではなくNSLogを表示する必要があります。2000

4

1 に答える 1