08月05日
UIAlertでテキスト編集
よくアラートダイアログ内でパスワードとか入力を求めるのがあるけど、標準ではそんな事出来ないので、中にUITextField仕込んであげましょう、ということで。
-
UIAlertView *alert = [[[UIAlertView alloc] init] autorelease];
-
alert.title = @"編集";
-
alert.message = @"編集してください。\n\n\n";
-
alert.delegate = self;
-
-
UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 70.0, 245.0, 25.0)];
-
[field setBackgroundColor:[UIColor whiteColor]];
-
[alert addSubview:field];
-
-
[alert addButtonWithTitle:@"キャンセル"];
-
[alert addButtonWithTitle:@"実行"];
-
alert.cancelButtonIndex = 0;
-
-
[alert show];
-
-
[field becomeFirstResponder];
-
[field release];
んで、クリック後の処理は…
-
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
-
if (buttonIndex != alertView.cancelButtonIndex) {
-
for (UIView *subView in alertView.subviews) {
-
if ([subView isKindOfClass:[UITextField class]]) {
-
NSString *text = [(UITextField *)subView text];
-
}
-
}
-
}
-
}
UITextFieldが1個しか追加されてない事が前提のテキスト取得方法ですけどね〜
現状の構成がUITabControllerの上にUIViewControllerが3つ載ってて、うち2つがUINavigationControllerでかつUITableViewという感じになってます。
Appleのガイドラインに引っかかってしまわないかと戦々恐々ではあるんですが、上手い事行ったらそこら辺のTipsも出していければ。
さ〜申請はいつになるかな〜
コメント & トラックバック
コメントフィード
コメント