简体   繁体   English

IBOutlets没有显示

[英]IBOutlets not showing

I created three IBOutlet s in a .h but when I go to Interface Builder and go to Referencing Outlets or right click on the object that I want to connect to one of the outlets. 我在.h中创建了三个IBOutlet ,但是当我转到Interface Builder并转到“引用插座”或右键单击要连接到其中一个插座的对象时。 It just doesn't display the outlets I made. 它只是不显示我所做的出口。 How do I find and connect the images in IB to these. 我如何找到IB中的图像并将其连接到这些图像。 My goal is to make custom buttons, I have the images out in IB and have set the highlighted state. 我的目标是制作自定义按钮,将图像放入IB并设置突出显示状态。 And I want the images to auto switch to the highlighted state when touchupInside is triggered. 我希望图像在触发touchupInside时自动切换到突出显示状态。

#import <UIKit/UIKit.h>


@interface FirstViewController : UIViewController {
    IBOutlet UIButton *brown
    IBOutlet UIButton *red
    IBOutlet UIButton *blue


}

-(void)brownPressed
-(void)redPressed
-(void)bluePressed
@end

If the code you posted is accurate, you are missing 6 semicolons. 如果您发布的代码正确无误,则说明您缺少6个分号。 Interface Builder won't be able to properly parse the header file without them and so it won't show any IBOutlet s. 如果没有它们,Interface Builder将无法正确解析头文件,因此它不会显示任何IBOutlet

Try changing the code to the following: 尝试将代码更改为以下内容:

@interface FirstViewController : UIViewController {
    IBOutlet UIButton *brown;
    IBOutlet UIButton *red;
    IBOutlet UIButton *blue;

}

-(void)brownPressed;
-(void)redPressed;
-(void)bluePressed;
@end

This answer is in reference to Xcode 4 该答案参考了Xcode 4

If you changed the name of the .xib manually, don't forget to check these IB setting in the right pane: 如果您手动更改了.xib的名称,请不要忘记在右窗格中检查以下IB设置:

Identity and Type: File Name should be: 身份和类型:文件名应为:

newName.xib newName.xib

Custom Class : Class should be: 自定义类别:类别应为:

newName 新名字

... ...

I was also experiencing this problem - after changing the .xib filename manually. 我也遇到了这个问题-手动更改.xib文件名之后。 I have no idea why renaming by refactoring was grayed out but that was my first attempted solution to rename. 我不知道为什么通过重构进行的重命名显示为灰色,但这是我第一次尝试重命名的解决方案。 I then made some IBOutlets, but dragging to the File's Owner didn't give me any options to connect to it. 然后,我制作了一些IBOutlets,但是拖动到文件的所有者并没有给我任何连接到它的选项。

I right clicked on File's Owner and noticed some warnings telling me there was no IBOutlet by the name of the variable it tried to reference. 我右键单击“文件的所有者”,发现一些警告告诉我,它尝试引用的变量名不存在IBOutlet。

Basically, since I changed the .xib filename manually, at least one of the above configurations did not automatically follow (makes sense since I did a manual operation). 基本上,由于我手动更改了.xib文件名,因此至少其中一种配置没有自动遵循(因为我进行了手动操作,因此很有意义)。

这发生在我身上,尝试将按钮的内部修饰连接到文件所有者,然后它将显示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM