我将UITextField放入UIAlertView并将其向上移动,以便键盘不会使用以下代码覆盖它:
[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];
Run Code Online (Sandbox Code Playgroud)
我还有以下代码来处理警报视图:
- (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
}}
Run Code Online (Sandbox Code Playgroud)
我还有一个UIAlertViewExtended.h文件,其中包含:
@class UITextField, UILabel;
@interface UIAlertView(Extended)
-(UITextField *)textField;
@end
Run Code Online (Sandbox Code Playgroud)
我的问题是如何获取用户输入的文本以及如何解除键盘?
谢谢,本
在我的应用程序中,我想显示一个登录屏幕 - 当应用程序启动时以及应用程序变为活动状态时将显示该屏幕.作为参考,我使用的是故事板,ARC,它是一个标签栏应用程序.
因此,我需要在方法中执行以下过程applicationDidBecomeActive
:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if ( ... ) { // if the user needs to login
PasswordViewController *passwordView = [[PasswordViewController alloc] init];
UIViewController *myView = self.window.rootViewController;
[myView presentModalViewController:passwordView animated:NO];
}
}
Run Code Online (Sandbox Code Playgroud)
在某种程度上这确实有效 - 我可以调用一个方法,viewDidAppear
其中显示一个警报视图以允许用户登录.但是,这是不可取的,我想有一个登录文本框和其他ui元素.如果我不调用我的登录方法,即使我在视图上放置了标签和其他元素,也没有任何反应并且屏幕保持黑色.
有谁知道解决这个问题的方法?我的密码视图嵌入在导航控制器中,但与主故事板分离.
我需要添加一个4位数的引脚视图控制器,它将"悬停"在我的应用程序的主窗口上,并防止不知道该引脚的用户浏览应用程序中的数据.
我很感兴趣,如果有任何演示项目或开源项目完成此功能(按键点击,自动更改焦点,显示静态光泽键盘,锁定x秒后).
谢谢您的意见!