Interface Builder不允许连接到自定义UIView类? [英] Interface Builder won't allow connections to custom UIView class?

查看:97
本文介绍了Interface Builder不允许连接到自定义UIView类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Xcode 4.3.3,我无法弄清楚如何将自定义UIView类中的出口与Interface Builder中创建的对象连接起来。

Using Xcode 4.3.3, I can't figure out how to connect outlets in a custom UIView class with objects created in Interface Builder.

在一个ViewController中,我有各种各样的按钮,滑块等,我试图将它们分组到Views中。因此,在IB的ViewController中,我添加了3个视图。在任何给定时间只能看到1个视图。

In one ViewController, I have a variety of buttons, sliders, etc that I'm trying to group into Views. So, within that ViewController in IB, I added 3 views. Only 1 view will be visible at any given time.

我派生了自定义UIView类来处理这3个视图中的每一个。我的视图控制器实例化每个类。我在IB中选择了视图,打开了Identity Inspector并将Class设置为我的自定义类。但是当我尝试将视图中的连接和/或它的组成控件拖动到自定义视图的.h文件时,IB将不会添加连接。

I derived custom UIView classes to handle each of these 3 views. My view controller instantiates each of the classes. I selected the view(s) in IB, opened the Identity Inspector and set the Class(es) to my custom class(es). But when I tried dragging connections from the view and/or it's constituent controls to the custom view's .h file IB won't add a connection.

IB允许我添加通过拖动到父视图控制器的.h而不是自定义视图的.h文件的出口/操作。我想过,一旦我将View的类设置为我的自定义类,我就可以将视图组件的出口拖到我的自定义类而不是视图控制器中。

IB allows me to add outlets/actions by dragging to the parent view controller's .h, but not to the custom view's .h file. I thought once I set the View's class to be my custom class, I could drag outlets for the view's components to my custom class rather than in the view controller.

这个问题与我的问题相同:如何将UIview插座连接到自定义子视图这两个解决方案(手动添加插座并在IB中设置视图的类)并没有改变我的行为。以下是我添加的手册:

This question seems identical to mine: how to connect UIview outlets to a custom subview The two solutions (manually adding outlets and setting the view's class in IB) did not change the behavior for me. Here are the manual outlets I added:

customView3.h

customView3.h

#import <UIKit/UIKit.h>

@interface customView3 : UIView

@property (retain) IBOutlet customView3 *view3;
@property (retain) IBOutlet UISlider *slider;

@end

customView3.m

customView3.m

#import "customView3.h"

@implementation customView3

@synthesize view3, slider;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
    // Initialization code
    }
    return self;
}
@end

我在这里缺少什么?除了视图控制器之外,我还需要设置/检查以便添加插座吗?

What am I missing here? What else do I need to set/check in order to add outlets to my custom UIView rather than the view controller?

推荐答案

注意我今天确实让它工作,但不得不在派生类中手动插入/输入插座,然后我可以从头文件拖到故事板中的UI元素,但不是相反。

Note that I did get this to work today, but had to insert/type the outlets by hand in the derived class, then I could drag from the header file to the UI element in the Storyboard, but not the other way around.

这篇关于Interface Builder不允许连接到自定义UIView类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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