@Synthesize IBOutlet (UIScrollView) 不起作用

发布于 2024-12-26 05:13:45 字数 601 浏览 1 评论 0原文

这是关于未正确合成的出口(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

天涯离梦残月幽梦 2025-01-02 05:13:45
  1. 确保您确实将 UIScrollView 连接到了插座。
  2. 请记住,只有在从笔尖加载视图之后才会设置scrollView。
  1. Make sure that you actually connected a UIScrollView to the outlet.
  2. Keep in mind that scrollView won't be set until after the view has been loaded from the nib.
守护在此方 2025-01-02 05:13:45

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.

眼睛会笑 2025-01-02 05:13:45

如果您想与 Outlet 合作并使用用户将看到的实际尺寸(包括导航栏、选项卡栏等),您必须在 viewWillAppearviewDidAppear 实现所有 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 or viewDidAppear.
Read more about stages of loading view from nib.

墨小沫ゞ 2025-01-02 05:13:45

尝试删除滚动视图的本地声明,

@interface VC_Create_Preview : UIViewController <UIScrollViewDelegate> {
    UIScrollView *scrollView;//remove this
}

它可能会帮助你。另外,在分配时使用 _scrollView 而不是 scrollView

Try removing local declaration of scrollview i.e.

@interface VC_Create_Preview : UIViewController <UIScrollViewDelegate> {
    UIScrollView *scrollView;//remove this
}

It may help you. Also while allocating use _scrollView instead of scrollView.

岛歌少女 2025-01-02 05:13:45

确保您在代码中使用正确的类,例如,您放入故事板的第一个 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 original UIViewController 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文