UILabel内容更新有关问题
UILabel内容更新问题我在新建一个通过IB创建的UIViewController之后,对立面的UILabel进行了编辑,然后显示
UILabel内容更新问题
我在新建一个通过IB创建的UIViewController之后,对立面的UILabel进行了编辑,然后显示出来,但是发现UILabel立面的内容根本没有改变。这是为什么?
NewViewController *newViewController = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
[newViewController.textLabel setText:@"Just Change Text"];
[self.navigationController pushViewController:newViewController animated:YES];
[最优解释]延迟加载的问题 在viewController 初始化后里面的view还没有载入
只有push的时候才会载入view
newViewController.textLabel 应该是0x0....
[其他解释]顶一个,我也常遇到这样的问题。objective-c的规则比较宽松,如果对一个零指针发送消息(即函数调用),是不会产生任何错误的,所以很容易让人产生错觉——代码无错。解决方法就是在view controller的viewDidLoad 方法中对view的数据进行初始化。
[其他解释]好象有看过此类问题
把[newViewController.textLabel setText:@"Just Change Text"];
放到[self.navigationController pushViewController:newViewController animated:YES];后面。刷新问题的说。。。
[其他解释]newViewController.textLabel 此时的textLabel应该为nil,因为通过xib创建的uilabel,需要viewdidload内才真正加载。
[其他解释]看一下是否连线?好久没用过IB了。
[其他解释]应该是连线问题
[其他解释]给你出一馊主意,先把label背景色涂成特别的颜色,,,看看能不能显示
如果能显示的话,那就是文字的问题啦
[其他解释]此主意不馊,很实用的调试方法
[其他解释]嘿嘿~Good Idea~