gpt4 book ai didi

ios - iOS View 上的自定义 subview 有空 socket

转载 作者:行者123 更新时间:2023-12-01 19:02:55 27 4
gpt4 key购买 nike

我有一个名为 FeedView 的 View ,由 FeedViewController 处理。

我还有一个名为“NearestStore”的 XIB,它由一个名为“NearestStoreViewController”的 View Controller 处理。 NearestStore xib 有标签、按钮等。在 View Controller 中,我有连接到 NearestStore.xib 中 subview 的 socket 。

NearestStore 继承自 UIButton (因此更容易处理点击事件)。

在 FeedViewController.xib 上,我有一个设置为 NearestStore 类型的 UIButton。

到现在为止还挺好。这是在我的 FeedViewController 上:

__weak IBOutlet NearestStoreButton *btn_nearestStore;

导出在xib上连接到导出。

NearestStoreViewController 有几个 subview 的导出,例如:
@property (nonatomic, weak) IBOutlet  UILabel *lbl_distance; 
@property (nonatomic, weak) IBOutlet UIImageView *img_distance;

出于某种原因,在我的 FeedViewController 上,对 btn_nearestStore 的引用很好,但所有 subview 都为零。

例如:
btn_nearestStore.lbl_distance 

是零

我错过了什么?

最佳答案

这听起来与系统应该工作的完全一样。使用 xibs 创建自定义小部件并不容易。
以下是它的工作原理:
您的 FeedViewController 将为相应的 FeedView 执行 xib 加载。
在此加载期间,它会注意到 NearestStoreButton subview 。因此,它使用 - (id)initWithCoder: 创建这样的 View 。 NearestStoreButton 类上的消息。它不会神奇地注意到相应的 .xib 或相应的 viewController。
如果您需要在 xib 中使用 xib,则需要为所有 subview 手动加载。请记住,您需要以某种方式为这些辅助 xib 创建/使用适当的所有者( View Controller )。

关于ios - iOS View 上的自定义 subview 有空 socket ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21652142/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com