本文介绍了如何在mainViewController.m中调用awakeFromNib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含自定义单元格的xib文件。我正在尝试访问`customCell.m`中创建的对象的高度。



这是我的代码:



I have an xib file containing a custom cell. I'm trying to access the height of an object created in `customCell.m`.

Here is my code:

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
    }

推荐答案


这篇关于如何在mainViewController.m中调用awakeFromNib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 16:13