ここに、UILabelを持つ別のクラスにString値を渡し、それを表示するクラスがあります。ただし、別のクラスのラベルに表示することはできません。私はこれを2つの方法で行いました。
1)私の最初の方法、別のクラスからラベルを直接呼び出す。私の最初のクラスでは、メソッド
static void on_status_state(NSString *) stats
{
DisplayViewController* display = [[DisplayViewController alloc] init];
display.statusLabel.text = @"Sample Display";
}
UILabelを含むクラス。DisplayConn.hで
@property (retain, nonatomic) IBOutlet UILabel *statusLabel;
2)2番目の方法、メソッドを呼び出して、メソッドの最初のクラスのパラメーターに値を渡す
static void on_status_state(NSString *) stats
{
DisplayViewController* display = [[DisplayViewController alloc] autorelease];
[display toReceiveStatus:@"Sample Label"];
}
UILabelを含むクラス。DisplayConn.hで
@property (retain, nonatomic) IBOutlet UILabel *statusLabel;
次にDisplayConn.mで
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)toReceiveStatus:(NSString *) stats
{
self.statusLabel.text = stats;
NSLog(@"DISPLAY %@",stats);
}
値を含むログが表示されるため、2番目の方法は機能しているように見えますが、値はまだlabel('statusLabel')に表示されません。ラベルの表示は、実行時に時々変更されます。原因は何ですか?