我正试图在键盘显示时向上移动视图,因此它不会掩盖屏幕,但由于某种原因,它-(void)DidBeginEditing: (UITextField *)textfield无法正常工作.
- (void)textFieldDidBeginEditing:(UITextField *)ga1
{
/* should move views */
self.view.center = CGPointMake(self.view.center.x, self.view.center.y + 220);
}
- (void)textFieldDidEndEditing:(UITextField *)ga1
{
/* should move views */
self.view.center = CGPointMake(self.view.center.x, self.view.center.y - 220);
}
Run Code Online (Sandbox Code Playgroud)
它也没有进入方法,谁能告诉我为什么?
如何检查iphone应用程序,如果URL有效,那么它应该打开它,否则它可能会显示它是无效的URL.我正在使用以下代码,但问题是,如果我输入www.google.com它显示有效,如果我输入nice.com也显示有效.
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField setUserInteractionEnabled:YES];
[textField resignFirstResponder];
test=textField.text;
NSLog(@"Test is working and test is %@",test);
if ([self urlIsValiad:test]) {
NSURL *url = [NSURL URLWithString:test];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView setScalesPageToFit:YES];
[self.webView loadRequest:request];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please enter Valid URL" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
return YES;
}
- (BOOL) urlIsValiad: (NSString *) url
{
NSString *regex =
@"((?:http|https)://)?(?:www\\.)?[\\w\\d\\-_]+\\.\\w{2,3}(\\.\\w{2})?(/(?<=/)(?:[\\w\\d\\-./_]+)?)?";
/// OR use this
///NSString *regex = "(http|ftp|https)://[\w-_]+(.[\w-_]+)+([\w-.,@?^=%&:/~+#]* [\w-\@?^=%&/~+#])?";
NSPredicate …Run Code Online (Sandbox Code Playgroud) 我们可以在UIAlertView的文本域iOS7中以编程方式插入文本
在IOS7中使用textinput创建了UIAlertView.任何人都可以帮助我"在文本字段中以编程方式插入文本"吗?
我有一个数据录入应用程序,我主要使用iOS7开发,但它将支持ios 6.我注意到UITextField当我尝试在iOS6中验证表单时检查是否为空时它会告诉我它如果那里有占位符文本,则不为空.在iOS 7中我没有这个问题.
有没有人有任何有效的解决方案除了将每个UITextField's内容与其placeholdet文本匹配UITextFields整个应用程序中的所有内容?
编辑:
如果验证是问题,这是我的验证码.很简单,我使用强制执行迭代数组UITextFields并检查它们中是否有任何输入.
-(void)checkIfComplete{
BOOL complete = YES;
for(int i = 0; i < self.mandatoryFields.count; i++){
UITextField *tempTextField = self.mandatoryFields[i];
if([tempTextField.text isEqual: @""]){
complete = NO;
}
}
if(complete){
self.btnSave.enabled = YES;
}else{
self.btnSave.enabled = NO;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑2:
Okey这很奇怪.当我加载ViewController时,UITextFields验证是错误的(它表示表单已完成,即使它不是).但是,如果我输入a UITextField,写一些内容然后删除我刚才写的内容,验证是正确的(它表示形式是不完整的).如果这有任何区别,我将从故事板中设置我的占位符.
谢谢
我用
[self.assuntoTextField addTarget:self action:@selector(testarSeTemTexto) forControlEvents:UIControlEventEditingChanged];
得到的文本值UITextFields,但我不能这样做UITextViews,我怎么能这样做用户仍在编辑TextView?
这是我的问题.我创建了一个UITextField.
.h文件:
@property (strong, nonatomic) UITextField *emailTextField;
Run Code Online (Sandbox Code Playgroud)
.m文件:
- (void)viewDidLoad
{
[super viewDidLoad];
self.emailTextField.delegate=self;
[self setTextFields:120 :@" email" :self.emailTextField];
}
-(void)setTextFields:(float)ycoord :(NSString *)text :(UITextField *)textField
{
CGRect frame = CGRectMake(60, ycoord, 180, 30);
textField = [[UITextField alloc]initWithFrame:frame];
textField.backgroundColor = [UIColor whiteColor];
textField.placeholder = text;
textField.font = [UIFont fontWithName:@"Baskerville" size:15];
textField.allowsEditingTextAttributes=YES;
textField.autocorrectionType = UITextAutocorrectionTypeNo;
CALayer *lay = [textField layer];
[lay setCornerRadius:5.0f];
[self.view addSubview:textField];
}
Run Code Online (Sandbox Code Playgroud)
目的是保存用户放在TextField中的文本.我尝试了委托方法
-(void)textFieldDidEndEditing:(UITextField *)textField
Run Code Online (Sandbox Code Playgroud)
但是没有调用该方法(我把一个NSLog检查).有人可以帮忙吗?
所以我有3个文本域.它们被清除后,我想占位符STILL留在那里.到目前为止,在过去的一周里,我一直在与这个问题作斗争,没有人能够帮助我解决这个问题.我想知道这是否可能?...
这是我清除它后设置占位符的示例代码:
personYouOweMoney.text = @" ";
amtYouOwe.text = @" ";
self.cellNum.text = @" ";
personYouOweMoney.placeholder = @"Name of person you owe";
amtYouOwe.placeholder = @"Amount Owed (USD)";
self.cellNum.placeholder = @"Their cell number";
Run Code Online (Sandbox Code Playgroud)
感谢所有帮助,提前感谢
我正在访问搜索栏的文本字段.这不断变化
对于我正在使用的iOS 6
textField = [searchbar.subviews objectAtIndex:1];
Run Code Online (Sandbox Code Playgroud)
它在iOS 7中有一个视图,并且有一个子视图,我们可以从中获取textField,所以我使用以下代码用于iOS 7或更高版本的iOS
UIView *searchbarview = [searchbar.subviews objectAtIndex:0];
NSLog(@"searchbarview.subviews Array is %@",searchbarview.subviews.description);
textField = (UITextField *)[searchbarview.subviews objectAtIndex:1];
Run Code Online (Sandbox Code Playgroud)
现在自iOS 7.1以来,searchbarview只有一个子视图是UISearchBarBackground,与iOS 7.0不同,它有两个子视图,所以即使我使用for循环遍历所有子视图,我也无法获得textField
任何人都可以帮我这个谢谢,
编辑 这是searchbarview.subviews返回的数组的日志,你可以看到它只返回一个UISearchBarBackground对象,所以我想知道UITextField对象在哪里
searchbarview.subviews Array is (
"<UISearchBarBackground: 0xe6bc9d0; frame = (0 0; 768 50); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xe6bcb20>>"
)
Run Code Online (Sandbox Code Playgroud) 好吧标题说它主要是:
是否有准备好的UITextField组件可以在标签中采用数字(最大文本长度)?如果也可以显示数字也会很酷.
那里有组件吗?
我想拥有什么:
为什么UITextField嵌入在a中时不会响应触摸事件UIView(它本身嵌入在原始视图控制器的主体中UIView)?
这是代码:
- (void)loadView
{
self.view = [UIView new];
UIView *positionalView = [[UIView alloc] initWithFrame:CGRectMake(20, 100, 280, 100)];
UITextField *usernameField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 280, 50)];
usernameField.placeholder = @"Full Name";
usernameField.delegate = self;
[usernameField addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
[positionalView addSubview:usernameField];
UITextField *passwordField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 280, 50)];
passwordField.placeholder = @"Password";
passwordField.delegate = self;
[passwordField addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
[positionalView addSubview:passwordField];
[self.view addSubview:positionalView];
}
Run Code Online (Sandbox Code Playgroud)
发现很难理解这种行为,因为上面的代码工作正常,如果我只是删除positionalView并直接将文本字段添加到主self.view.
有谁能解释一下?
ios ×10
uitextfield ×10
objective-c ×8
iphone ×2
xcode ×2
delegates ×1
ipad ×1
placeholder ×1
text ×1
uialertview ×1
uisearchbar ×1
uitextview ×1
uiview ×1
url ×1