如何在mainViewController.m中调用awakeFromNib [英] How do I Call awakeFromNib in mainViewController.m

查看:109
本文介绍了如何在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
    }

推荐答案

您还必须覆盖init函数abd approbiate值。我通常会编写一个在两者中调用的设置函数。



PS:阅读Apple文档以了解语言及其概念。
you must also overwrite the init function abd approbiate values. I normally write an setup function which is called in both.

PS: Read the Apple docs to understand the language and its concepts.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆