@dynamic label1;プロパティは、@dynamicというコンパイラディレクティブをつけて記述します。これは、実行時に動的にアクセサが生成される場合に使うものです。GUIコンポーネントを接続するプロパティは、静的にアクセサを用意することができませんので、必ず@dynamicを指定しておきます。
@dynamic field1;
id str = [field1 text];textはUITextFieldに記述されているテキストをNSStringとして取得するものです。これで書かれたテキストを変数に取り出します。
id msg = [NSString stringWithFormat:@"Hello, %@!!",str];NSStringのstringWithFormat:を使い、"Hello, ◯◯!!"というテキストを生成します。
[label1 setText:msg];最後に、UILabelの表示テキストに変数を設定します。setText:は、引数のNSStringを表示テキストに設定するものです。
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
※MyIAppController.m #import "MyIAppViewController.h" @implementation MyIAppViewController @dynamic label1; @dynamic field1; - (IBAction)btn1Action:(id)sender { id str = [field1 text]; id msg = [NSString stringWithFormat:@"Hello, %@!!",str]; [label1 setText:msg]; } ……中略…… @end
<< 前へ |