在Interface Builder和XCode中连接UILabel? [英] Connect a UILabel in Interface Builder and XCode?

查看:110
本文介绍了在Interface Builder和XCode中连接UILabel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一些简单的事情,比如在XCode和IB中为View添加一个Label,我无法弄清楚如何去做。我在网上找到的所有样本都是旧版本的IB,因此说明不正确。

I am trying to do something as simple as add a Label to a View in XCode and IB and I can't figure out how to do it. All the samples I find online are for older versions of IB so the directions aren't correct.

我的.xib文件中有一个标签,在我的Controller.h中文件我有一个IBOutlet UILabel声明了一个属性设置。

I have a label on my .xib file, in my Controller.h file I have an IBOutlet UILabel declared with a Property set up.

在我的Controller.m文件中,我合成了该属性。

In my Controller.m file I synthesized that Property.

在Interface Builder中,我不能为我的生活找出如何将我的代码中的标签与.xib上的Label相关联。
每当我尝试将Connection连接到File的Owner时,唯一显示的选项是View。

In Interface Builder, I cannot for the LIFE of me figure out how to associate my label in my code with the Label on the .xib. Whenever I try to drag the Connection to File's Owner, the only option that shows up is "View".

如果我查看Library下的Controller Interface Builder的窗口,Label在Outlets下显示为UILabel。我很确定它曾经是一个类型id,但它自动显示为UILabel,如果我尝试添加id,它也不起作用。

If I look at the Controller under the Library Window of Interface Builder, the Label shows up as a UILabel under Outlets. I am pretty sure that it used to be a type "id", but it automatically shows up as UILabel and if I try to add an "id" one, it doesn't work either.

有人能指点我到某个地方来解释这个愚蠢的事吗?使标签有文本不应该这么困难。

Can someone point me to somewhere to explain this stupid thing? It should not be this difficult to make a label have text.

推荐答案

假设您的视图名为ExampleView。单击文件所有者,然后按⌘+ 4。这将突出显示身份框。确保类名与类的名称相同。

Assuming your view is called ExampleView. Click on the file owner and then press ⌘+4. This will highlight the identity box. Make sure that the class name is the same as the name of your class.

保存并关闭Interface Builder,然后进入Xcode并验证:

Save and close Interface Builder and then go into Xcode and verify:

// ExampleViewController.h
#import <UIKit/UIKit.h>

@class ExampleViewController;
@interface ExampleViewController : UIViewController {

    IBOutlet UILabel *label;
}

@property (retain, nonatomic) IBOutlet UILabel *label;

@end

在你的.m文件中:

// ExampleViewController.m
#import "ExampleViewController.h"

@implementation ExampleViewController

@synthesize label;

然后保存xcode文件并打开ExampleView。将标签拖到视图上。您不应该将该标签连接到文件所有者。

Then save the xcode files and open up your ExampleView. Drag a label onto the view. You are not supposed to connect that label to the Files owner.

INSTEAD您点击文件框。 HIT⌘+ 2这将打开连接框。然后你会看到你的出路。点击并将其与您的标签相关联。

这篇关于在Interface Builder和XCode中连接UILabel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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