- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
美好的一天!
我有一个 UITableView
和两个单元格及其相应的 UITextField
。我通过for循环创建了UITextField:
- (UITextField *)createInformationTextField:(NSString *)createInformationTextField createInformationPlaceholder:(NSString *)createInformationPlaceholder
{
for (int i = 0; i < 2; i++) {
informationTextField = [[UITextField alloc] initWithFrame:CGRectMake(120, 12, 170, 30)];
informationTextField.autocapitalizationType = UITextAutocapitalizationTypeWords;
informationTextField.autocorrectionType = UITextAutocorrectionTypeNo;
informationTextField.placeholder = createInformationPlaceholder;
informationTextField.text = createInformationTextField;
informationTextField.adjustsFontSizeToFitWidth = YES;
informationTextField.clearButtonMode = UITextFieldViewModeAlways;
informationTextField.tag = i;
}
return informationTextField;
}
我的cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *name;
NSString *address;
switch (indexPath.section) {
case 0:
cell.selectionStyle = UITableViewCellSelectionStyleNone;
switch (indexPath.row) {
case 0:
informationTextField = [self createInformationTextField:name createInformationPlaceholder:[NSString stringWithFormat:@"%d", informationTextField.tag]];
cell.textLabel.text = @"Name";
[cell addSubview:informationTextField];
break;
case 1:
informationTextField = [self createInformationTextField:address createInformationPlaceholder:[NSString stringWithFormat:@"%d", informationTextField.tag]];
cell.textLabel.text = @"Address";
[cell addSubview:informationTextField];
break;
default:
break;
}
break;
case 1:
switch (indexPath.row) {
case 0:
cell.textLabel.text = @"State";
break;
default:
break;
}
break;
default:
break;
}
informationTextField.delegate = self;
return cell;
}
我设置了 UITableView
占位符来显示其相应的标签,并且工作正常。
屏幕截图:
问题出在我的textFieldDidEndEditing
中:
- (void)textFieldDidEndEditing:(UITextField *)textField
{
switch (textField.tag) {
case 0:
NSLog(@"Name Field. The tag is %d", textField.tag);
break;
case 1:
NSLog(@"Address Field. The tag is %d", textField.tag);
break;
default:
break;
}
}
在用户在 UITextField
中输入内容后,我尝试再次输出其标签,但这就是我所看到的
2013-06-06 17:36:53.050 UITableUITextField[20387:c07] Address Field. The tag is 1
2013-06-06 17:36:55.636 UITableUITextField[20387:c07] Address Field. The tag is 1
最佳答案
您正在调用createInformationTextField方法来创建文本字段。我认为您正在从每个单元格调用此方法。因此,当您调用此方法时,它会进入 for 循环,经过两次循环后,它会返回每个单元格都带有标记 1 的文本字段。这就是为什么你为每个文本字段获得标签 1 的原因。尝试从您的 cellForRowAtIndexPath: 方法
调用以下方法 - (UITextField *)createInformationTextField:(NSString *)createInformationTextField createInformationPlaceholder:(NSString *)createInformationPlaceholder index:(NSIndexPath*)indexPath
{
UITextField *informationTextField = [[UITextField alloc] initWithFrame:CGRectMake(120, 12, 170, 30)];
informationTextField.autocapitalizationType = UITextAutocapitalizationTypeWords;
informationTextField.autocorrectionType = UITextAutocorrectionTypeNo;
informationTextField.placeholder = createInformationPlaceholder;
informationTextField.text = createInformationTextField;
informationTextField.adjustsFontSizeToFitWidth = YES;
informationTextField.clearButtonMode = UITextFieldViewModeAlways;
informationTextField.tag = indexPath.row;
return informationTextField;
}
关于ios - 为什么我的 textFieldDidEndEditing 标签不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16958532/
有没有办法在不使用textFieldDidEndEditing的情况下检测键盘上的返回键被按下。例如,如果您执行关闭键盘的 segue,也会触发 textFieldDidEndEditing。 最佳答
我正在尝试创建一个计算器,该计算器可以在 UITextField 值发生更改时计算结果。 没有提交按钮我认为textFieldDidEndEditing。除了用户输入值的 UITextField 之外
您好,我正在使用以下代码来禁用 2 个 UIButtons,直到四个 UITextField 中有数据 - (void)textFieldDidBeginEditing:(UITextField *)
我正在开发一个使用核心数据的简单应用程序。我有一个带有文本字段的详细信息屏幕,当我单击完成按钮时我想保存它。现在,已完成的操作在调用 textFieldDidEndEditing 之前完成。 (使用
在我的应用程序中,我的 UITextFields 位于键盘顶部的下方,因此我必须向上移动我的 View ,以便在我编辑时可以在键盘上看到文本字段。为此,我使用 UITextFieldDelegate
可能是一个简单的答案, 我怎样才能通过 textField.text来自具有文本字段的 UIAlertView 到 -(void)alertView:(UIAlertView *)alertView
我正在使用以下内容根据文本字段totalAmountInc更新金额VAT func textFieldDidEndEditing(textField: UITextField) { if to
在我的一个项目中,当键盘显示并按下完成按钮时,我首先调用 textFieldDidEndEditing,然后它将触发 UIKeyboardWillHideNotification 的目标函数。然而,在
美好的一天! 我有一个 UITableView 和两个单元格及其相应的 UITextField。我通过for循环创建了UITextField: - (UITextField *)createInfor
当以下文本字段收到代码第二部分中的条件时,我想要一个警报 self.circuit.rcdAtIan = [ICUtils nonNilString:self.rcdAtIan.text]; self
在我的主页中有四个文本字段。但我想在用户在 eamil 文本字段中编写电子邮件时调用方法。 注意:我只想在用户键入电子邮件文本字段时调用方法。我不想在其他文本字段上调用方法。 这是我尝试过的:: fu
我有一个多 View 进程,用户正在输入数据,并且我在整个过程中的每一步都将其保存到模型类属性中。 我使用 textFieldDidEndEditing 检查输入是否有效,如果有效,则保存输入的数据。
UITextFieldDelegate 的事件序列有问题。 我有两个 UITableView A 和 B,它们由两个 UIViewController A 和 B 托管,它们本身由一个容器 View
我有一个 UITextField,在其中输入文本时,我想从文本字段中获取 doubleValue 并执行一些计算并将它们显示在 UITableView 中。 UITextField 的委托(deleg
出于某种原因,我不明白为什么在填写文本时我的按钮无法启用。 这就是我的设置方式。 override func viewDidLoad() { super.viewDidLoad() c
在 Swift 中,我有一个 UITextField、textA 和一个 UITextField、textB。 textA 有时会被禁用,但 textB 始终启用。 textA 被禁用: textA.
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and t
我有一个 ViewController,其中有一个用于用户输入的 TextField 和一个导航栏中的退出按钮。 通常,用户将文本输入到 textField 中,输入内容将在 textFieldDid
我试图在我的应用程序中隐藏我的 UITextField。我首先尝试使用 UIButton 来实现。 为此我做了这个: -(IBAction)hide:(id)sender { _textField.h
我有一个自定义的 UITableView,里面有 UITextFields。在 cellForRow... 中,我将 textFields 委托(delegate)给了自己。 (在我的主要 VC 类中
我是一名优秀的程序员,十分优秀!