私はかなり iPhone SDK に慣れていないので、この答えがばかげて明白である場合はご容赦ください。
.xib ファイルに接続された ViewController があります (それらは FirstViewController と呼ばれます)
MyCustomClass というカスタム クラスもあります。このクラスには、次のようなメソッドがあります。
- (void)setTheText {
[myLabel setText:@"foo"];
}
このメソッドを呼び出して、FirstViewController.xib のラベルにテキストを設定したい
これまでのところ、私はこれを行ってきました:
「オブジェクト」を Interface Builder にドラッグし、クラスを次のように設定します。 MyCustomClass IBOutlet 'myLabel' を MyCustomClass からビューの UILabel に接続しました。
ただし、プログラムを実行し、ボタンを押してラベル (FirstViewController.m にあります) を設定すると、次のようになります。
- (IBAction)doSomething:(id)sender {
MyCustomClass *customClass = [MyCustomClass alloc] init];
[customClass setTheText];
}
ただし、これは設定されません。NSLog(@"%@",[myLabel text]);
戻り値 (null)
Xcode にエラーや警告が表示されません。何が問題なのですか?
ありがとう、
マイケル
追加情報:
MyCustomClass.h へのインターフェイス:
#import <UIKit/UIKit.h>
@interface MyCustomClass : NSObject {
UILabel *myLabel;
}
@property (nonatomic, retain) IBOutlet UILabel *myLabel;
- (void)setTheText;
@end