【发布时间】:2008-12-17 21:33:32
【问题描述】:
我在 UIAlertView 中放置了一个 UITextField 并将其向上移动,这样键盘就不会被以下代码覆盖:
[dialog setDelegate:self];
[dialog setTitle:@"Enter Name"];
[dialog addButtonWithTitle:@"Cancel"];
[dialog addButtonWithTitle:@"OK"];
UITextField * nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 100.0);
[dialog setTransform: moveUp];
[dialog show];
我还有以下代码来处理警报视图:
- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%d", (int) buttonIndex);
if (buttonIndex == 1) { // OK pushed
NSLog([alert textField].text); // does not log anything
} else {
// Cancel pushed
}}
我还有一个 UIAlertViewExtended.h 文件,其中包含:
@class UITextField, UILabel;
@interface UIAlertView(Extended)
-(UITextField *)textField;
@end
我的问题是如何获取用户输入的文本以及如何关闭键盘?
谢谢, 本
【问题讨论】:
-
iPhone OS 4.0 似乎会自动进行转换,可能我们将不得不引入检查您的基础 SDK 是否为 4.0 并且您将支持的最低 SDK 为 3.0,以便仅执行 CGAffineTransform 代码如果本机操作系统是 3.0 或 3.1,对于 iPhone OS 4.0 跳过这部分代码!
标签: iphone cocoa-touch