基于自定义"XiB"的UI控件 [英] Custom 'XiB' Based UI Control

查看:74
本文介绍了基于自定义"XiB"的UI控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现自定义视图(等效于C#Custom UserControl)

I am trying to implement a custom view ( C# Custom UserControl equivalent )

用例:

  1. 我已经实现了基于UIView的自定义控件
  2. 该控件与专门的XiB文件( XIB文件A )相关联
  3. XiB的文件所有者"是专门的类,其中定义了IBOutlets
  4. 此控件由另一个XiB文件( XiB文件B )引用
  1. I have implemented a custom UIView based control
  2. The Control is associated with a specialized XiB file ( Xib file A )
  3. The 'File's Owner' of the XiB is a specialized class where IBOutlets are defined
  4. This control is referred to by a different XiB file ( XiB file B )

我希望在 XIB文件B 中呈现 XIB文件A 元素,但是,尽管所有IBOutlet都已正确关联,但未显示UI,并且'awakeFromNib ".

I was expecting Xib file A elements to be rendered within Xib file B, however, The UI wasn't presented although all IBOutlets were properly associated, and 'awakeFromNib' was called.

我在这里做什么错了?

以下是基于基于XiB的〜control〜的代码(由另一个XiB的另一个控件/视图引用)

The following is the code for the cusom XiB based ~control~ ( which is referred to by another control/view of a different XiB)

@interface SeriesView ()
@property (strong, atomic, readonly) MediaViewer* mediaViewer;
- (void) OnInitialize;
- (void) awakeFromNib;
@end

@implementation SeriesView

@synthesize mediaViewer = _mediaViewer;
@synthesize image = _image;
@synthesize scroll = _scroll;

- (id)initWithFrame:(CGRect)frame
{
    if(nil == (self = [super initWithFrame:frame]))
        return nil;
    [[NSBundle mainBundle] loadNibNamed:@"SeriesView" owner:self options:nil];
    return self;
}

- (id)initWithCoder:(NSCoder*)aDecoder
{
    if(nil == (self = [super initWithCoder:aDecoder]))
        return nil;
    [[NSBundle mainBundle] loadNibNamed:@"SeriesView" owner:self options:nil];
    return self;
}

- (void) OnInitialize
{
    _mediaViewer = [[MediaViewer alloc] init];
    _image.hidden= NO;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self OnInitialize];    
}
@end

推荐答案

每:

Per: UIView and initWithFrame and a NIB file. How can i get the NIB file loaded?

The only part missing was

  1. 在我的自定义视图中添加视图出口
  2. 将视图与相应的根视图@ XiB关联
  3. 通过awakeFromNib调用"[self addSubview:self.view]"

这篇关于基于自定义"XiB"的UI控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆