gpt4 book ai didi

ios - 使用 IBOutlets 初始化 View Controller 以自定义 View

转载 作者:行者123 更新时间:2023-11-29 01:49:48 25 4
gpt4 key购买 nike

我正在尝试找到一种方法来将具有 IBOutlets 的 View Controller 初始化为我在 XIB 中创建的自定义 View 。

这是我初始化类的代码:

MyContentViewController *pageContentViewController = [[MyContentViewController alloc] init];
self.pageContent = pageContentViewController;
[pageContentViewController view];

MyContentViewController 具有以下属性:

 @interface MyContentViewController : UIViewController

@property (nonatomic, weak) IBOutlet MyContentView *topLeftView;
@property (nonatomic, weak) IBOutlet MyContentView *topRightView;
@property (nonatomic, weak) IBOutlet MyContentView *bottomLeftView;
@property (nonatomic, weak) IBOutlet MyContentView *bottomRightView;

在 MyContentViewController xib 中,我有 4 个 View ,我已将它们设置为 MyContentView,并将上面的 IBOutlet 连接到 Storyboard 中的 View 。

enter image description here

自定义 View 定义如下:

#import <UIKit/UIKit.h>

@interface MyContentView : UIView

@property (nonatomic, strong) IBOutlet UILabel *labelView;

@end

但是,当我运行该应用程序时,我得到了我在 MyContentViewController xib 中添加的 4 个 View 。但是,它们都不显示自定义 UIView 中的 UILabel。

我在 MyContentView 中添加了以下内容:

- (void)awakeFromNib {
NSLog(@"VIEW AWAKE");
}

这会被打印出来,以便加载 View 。但是,如何使用 4 个 IBOutlets 来显示它们。

这是应用程序与 View 一起运行的图片。 4 个 View 上没有标签: enter image description here

最佳答案

我看到您的“MyContentView”有自己的 Nib 。从另一个 nib 加载具有 nib 布局的自定义 UIView 类有点复杂。

我认为这blog post包含答案

关于ios - 使用 IBOutlets 初始化 View Controller 以自定义 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31535781/

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