@Synthesize IBOutlet (UIScrollView) 不起作用
这是关于未正确合成的出口(UIScrollView)
在一种特殊情况下,我有一个接口声明为:
@interface VC_Create_Preview : UIViewController <UIScrollViewDelegate> {
UIScrollView *scrollView;
}
@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
并且在实现中......
@synthesize scrollView;
但在调试模式下我看到我的 self->scrollView 旁边总是有一个 0x0它。 执行像always这样的操作
CGRect frame = scrollView.frame;
会返回原点、高度、宽度为零(我怀疑是因为它没有正确合成)
0x0是否意味着它不指向内存中的任何位置? 这是否意味着它没有正确合成? 难道是IB中从outlet到scrollview的某个地方有一个断开的链接吗?
干杯 凯文
This is about an outlet not synthesising correctly (UIScrollView)
In one particular case, i have an interface declared as:
@interface VC_Create_Preview : UIViewController <UIScrollViewDelegate> {
UIScrollView *scrollView;
}
@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
And in the implementation....
@synthesize scrollView;
But in debug mode i see that my self->scrollView always has a 0x0 next to it.
Performing operations like
CGRect frame = scrollView.frame;
always returns a origin, height, width of zero (i suspect because it did not synthesise correctly)
Does 0x0 mean that it does not point to any location in memory?
Does this mean that it did not synthesize correctly?
Could it be that there is a broken link somewhere from the outlet to the scrollview in IB?
Cheers
Kevin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
0x0 表示空指针,您可能没有将scrollView 绑定到IB 中的滚动视图...这意味着viewControllers nib 在其视图中有一个scrollView 并绑定到插座。
0x0 means a null pointer, you probably have not tied the scrollView to a scroll view in IB...This means having the viewControllers nib have a scrollView in its view and tied to the outlet.
如果您想与 Outlet 合作并使用用户将看到的实际尺寸(包括导航栏、选项卡栏等),您必须在
viewWillAppear
或viewDidAppear
实现所有 UI 更改>.阅读有关从笔尖加载视图的阶段的更多信息。
If you want to work with outlets and use there real size that user will see (include navigation bar, tab bar, etc.) you must implement all UI changes at
viewWillAppear
orviewDidAppear
.Read more about stages of loading view from nib.
尝试删除滚动视图的本地声明,
它可能会帮助你。另外,在分配时使用
_scrollView
而不是scrollView
。Try removing local declaration of scrollview i.e.
It may help you. Also while allocating use
_scrollView
instead ofscrollView
.确保您在代码中使用正确的类,例如,您放入故事板的第一个
UIViewController
将具有通用的“whateveryourprojectisknown”UIViewController。然而,对我来说,问题是我随后将其链接到了其他几个 UIViewController,其中没有一个声明了自己的类,因此我正在编写的滚动器出口仅显示在主要原始版本上
UIViewController
这不是我需要的地方。因此,一旦我编写了自定义类名称,然后重新编写代码以适应该名称。插座看起来很完美并且工作正常。Be sure that you are using the correct class in your code, for example, the first
UIViewController
you drop into storyboard will have the generic "whateveryourprojectiscalled" UIViewController.However, the problem for me was that I then had that linked to several other
UIViewController
, none of which had there own class declared, so the scroller outlet I was writing, is only showing up on the main originalUIViewController
which is not where I needed it to be. So once I wrote a Custom Class name, and then re wrote the code to accommodate that. The outlet appeared perfectly and worked fine.