Hola!
KIMURAです。
今回はまず最初に周知事項から。
今月より、
TASAKI、
Oogamiが客先常駐となりましたので、今後しばらくは
KIMURA、
Koyanagiで記事を書いて行きますのでよろしくお願いします。
さてさて、今日は
UIViewに
addSubViewした時の話。
このブログの過去の記事で
TASAKIが書いている様に、ココ最近はInterfaceBuilderを使用していないのが現状です。。。
そうした場合、
UITextField、
UILabel等の部品をコード上で生成(alloc)し、プロパティの設定をして
addSubViewするのですが、UIViewのプロパティである「tag」に任意のユニークな値を設定することで、後からそのコントロールにアクセスすることが可能になります。
UITextField* textField;
textField = [[[ UITextField alloc] initWithFrame: CGRectMake( 21.0, 40.0, 274.0, 30.0 )]autorelease];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.clearButtonMode = UITextFieldViewModeAlways;
textField.keyboardAppearance = UIKeyboardAppearanceAlert;
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.tag = 10; textField.delegate = self;
[ xxxxx addSubview: textField ];
の様に設定し、他のメソッドからは
UITextField* textField = ( UITextField* )[ xxxxx
viewWithTag: 10 ];
でアクセスするということですね。
InterfaceBuilderを使用しない実装の場合に重宝します。
では、今日も遅いのでこの辺で。。。
Ciao!
- 関連記事
-
スポンサーサイト
trackbackURL:http://appteam.blog114.fc2.com/tb.php/120-55abdcf1