Xcode 和 UIScrollView 的问题
我似乎无法在代码中的插座与界面生成器中的实际对象之间建立工作连接。
我的 XIB 中有一个 UIScrollview,而 .h 中有一个 UIScrollview
IBOutlet UIScrollView *scrollView;
现在我将对象与插座连接起来,当我查看连接检查器时,我也看到了连接。在我的 .m 类文件中,我调用了 awakeFromNib 方法。这里我想从 UIScrollView 获取宽度和高度。
NSLog(@"Scrollview : %f,%f",scrollView.frame.size.width,scrollView.frame.size.height);
但我得到的只是这个:
滚动视图:0.000000,0.000000
我可以肯定地说它在 Interface Builder 中的大小为 320 x 160。
有什么想法吗?
I do not seem to be able to get a working connection between an outlet in the code and with the actual object in interface builder.
I have a UIScrollview in my XIB and this in my .h
IBOutlet UIScrollView *scrollView;
Now I connected the object with the outlet and I also see the connection when I look at the Connection Inspector. In my .m class file I have the method awakeFromNib which is called. Here I want to get the width and height from the UIScrollView.
NSLog(@"Scrollview : %f,%f",scrollView.frame.size.width,scrollView.frame.size.height);
But all I get is this :
Scrollview : 0.000000,0.000000
I can say for sure that it has a size of 320 by 160 in Interface Builder.
Any idea ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当谈到滚动视图时,棘手的事情发生了,你需要根据文档进行基本设置,如果你想要它滚动,请将滚动视图设置为大于屏幕尺寸,尝试600,600。另外,尝试获取 viewdidload 中的大小,看看会发生什么。
When it comes to scroll view, tricky happens, you need to set the basic settings based on docs, and if you want it scroll, make the scroll view bigger than the screen size, try 600,600. and also, try getting the size within viewdidload, and see what happens.
好吧,蒂尔给出了很好的暗示。它适用于 viewDidLoad 而不是 awakeFromNib。但是我仍然不知道为什么,因为我的理解是当所有连接准备好时 awakeFromNib 将被调用。
Well, Till gave a good hint. It works with viewDidLoad and not with awakeFromNib. However I still do not know why, since my understanding was that awakeFromNib will be called when all connections are ready.