UITableView
xib ファイルを使用するカスタム セルがあります。UILabel
高さ 200、幅 50 のをプログラムで作成しました。ラベルの幅と高さの in を実行すると、w: 50 と h: 200NSLog
が得られます。高さと幅。customCell.m
NSLog
mainViewController.m
なぜそうするのかわからない。ラベルの実際の高さを取得する必要がありますmainViewController.m
これが私のコードです:
customCell.m
- (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.
customCell *cellVC = [[cutsomCell alloc] init];
NSLog(@"%f, %f", cellVC.label.frame.size.height); // Results: 0.0000
}
xib ファイルを使用する場合、 atawakeFromNib
が呼び出されるはずがありませんか? そうでない場合、どのように呼び出すのですか?mainViewController.m
viewDidLoad
viewDidLoad