gpt4 book ai didi

iphone - IBOutlet 未在 Interface Builder 中连接 - Xcode 4.2

转载 作者:太空狗 更新时间:2023-10-30 03:46:39 24 4
gpt4 key购买 nike

我在这里阅读了其他问题,但它们似乎是针对 Xcode 3.2 或更早版本的,但与 4.2 无关。 :(

我开始了一个简单的项目,想在我的 xib 中连接文件所有者的导出。糟糕的是我的 IBOutlet 来 self 的 ViewController.h 没有过来。

我没有 10 或以上的声誉,所以 here is a screenshot of my File's Owner not showing my IBOutlets .

这是我的 ViewController.h 代码:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
IBOutlet UITextField *txtName;
IBOutlet UILabel *lblMessage;
}

@property (nonatomic, retain) IBOutlet UITextField *txtName;
@property (nonatomic, retain) IBOutlet UILabel *lblMessage;

- (IBAction)doSomething;

@end

这是我的 ViewController.m 代码:​​

#import "ViewController.h"

@implementation ViewController

@synthesize txtName;
@synthesize lblMessage;

- (IBAction) doSomething
{
NSString *msg = [[NSString alloc] initWithFormat:@"Hello, %@",txtName.text];
[lblMessage setText:msg];
}

@end

我是 Objective-C 和 Xcode 的新手,所以我可能犯了一个错误,但我已经学习了很多教程,但我永远无法显示我的 IBOutlets。我已经删除 Xcode 4.2 并重新安装以尝试解决此问题。这是一个 screenshot of my Xcode Version 4.2, Build 4D199 info .

还有其他人遇到过这个问题吗?感谢任何能指出我所犯错误的人。如果需要更多信息,请告诉我。

最佳答案

当您创建 IBAction 时,在 .h 文件中,它的左侧会有一个连接指示器。当它未连接时,它会显示一个空心圆圈。

按住它并将其拖动到您要连接的项目。我通常通过双击在新窗口中打开 XIB。

Connect the IBAction to your button by dragging from the the .h file


如果无法连接,您必须在 XIB 文件中设置 File's Owner。在占位符面板中选择 File's Owner。移至“实用程序”面板并确保 Identity Inspector 中的 Custom class 设置为您的 viewcontroller 的名称。

Set files owner

希望对您有所帮助。

干杯!

关于iphone - IBOutlet 未在 Interface Builder 中连接 - Xcode 4.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8352239/

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