【发布时间】:2010-01-21 20:25:28
【问题描述】:
我是 iPhone SDK 的新手,所以如果这个答案非常明显,请原谅我。
我有一个连接到 .xib 文件的 ViewController(它们被称为 FirstViewController)
我还有一个名为 MyCustomClass 的自定义类。在这个类中,我有一个这样的方法:
- (void)setTheText {
[myLabel setText:@"foo"];
}
我想调用这个方法在FirstViewController.xib的标签中设置文本
到目前为止,我已经这样做了:
将“对象”拖入Interface Builder,并将类设置为:MyCustomClass 将 MyCustomClass 中的 IBOutlet 'myLabel' 连接到视图中的 UILabel。
但是,当我运行程序并按下按钮设置标签(位于 FirstViewController.m 中)时,类似于:
- (IBAction)doSomething:(id)sender {
MyCustomClass *customClass = [MyCustomClass alloc] init];
[customClass setTheText];
}
但这并没有设置。 NSLog(@"%@",[myLabel text]); 返回(空)
Xcode 没有显示错误或警告,可能是什么问题?
谢谢,
迈克尔
附加信息:
MyCustomClass.h 的接口:
#import <UIKit/UIKit.h>
@interface MyCustomClass : NSObject {
UILabel *myLabel;
}
@property (nonatomic, retain) IBOutlet UILabel *myLabel;
- (void)setTheText;
@end
【问题讨论】:
-
你能把MyCustomClass的接口贴出来吗?你是如何在其中定义 myLabel 的?
标签: iphone xcode interface-builder uilabel