- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
iOS6
我在一个场景中有 6 个 UITextField,并带有一个可以转入下一个场景的按钮。
当我点击键盘上的“完成”按钮时,下面的代码效果很好:
- (IBAction)dismissKeyboard:(id)sender
{
if (sender == LocationName) {
self.meeting.LocationName = LocationName.text;
}
if (sender == LocationAddress) {
self.meeting.LocationAddress = LocationAddress.text;
}
if (sender == LocationCity) {
self.meeting.LocationCity = LocationCity.text;
}
//I have 3 more text fields after and then I persist to CoreData:
NSError *error = nil;
if (![managedObjectContext save:&error]) {
}
[sender endEditing:YES];
}
如果用户点击键盘上的“完成”按钮,数据将保存良好。
但是,如果用户单击导航栏上的“下一步”按钮,而没有先单击键盘上的“完成”按钮,则用户在 UITextfield 中键入的内容不会保存。我希望当用户点击导航栏上的“下一步”按钮调用下一个场景时,用户在所有字段中键入的数据(用户从键盘输入的数据)将被保存。
我有以下用于“下一步”按钮的代码:
- (IBAction)nextButtonPressed:(id)sender {
[self dismissKeyboard:sender];
}
我知道 nextButtonPressed 的代码是错误的。我想我需要帮助来识别哪个 UITextField 调用键盘可见,然后调用解雇键盘并将发送者作为参数传递。
谢谢
最佳答案
利用 UITextField
委托(delegate)方法 textFieldDidEndEditing:
了解焦点何时离开文本字段。此时您应该保存其数据。当焦点移动到另一个文本字段或键盘完全关闭时,将调用此函数。
您的 nextButtonPressed:
实现应该简单地对下一个文本字段是什么调用 becomeFirstResponder
。就是这样。通过将另一个文本字段设置为第一响应者,前一个文本字段将调用其 textFieldDidEndEditing:
委托(delegate)。
更新:
// This assumes the LocationXXX are instance variables referencing the UITextFields
- (IBAction)nextButtonPressed:(id)sender {
if (sender == LocationName) {
[LocationAddress becomeFirstResponder];
} else if (sender == LocationAddress) {
[LocationCity becomeFirstResponder];
// add the rest as needed
}
}
关于ios - 当“下一步”按钮调用转入下一个场景时保存 UITextField 数据(用户输入),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15074262/
这个问题已经有答案了: How do I convert NetBeans form and its class to something usable in IntelliJ IDEA form e
我有以下 JavaScript 代码,需要在 PHP 文件中执行。我需要知道如何在这段 javascript 代码中输入 php 标签。 我是网络编程新手。 这里使用的javascript是将html
我正尝试在 Swift 中完成以下任务,但需要一些帮助。 它是一个静态表,当一个单元格被选中时,我需要它来将该单元格的文本保存在一个变量中,并推送到我的下一个 View 。我正在使用 prepareF
在我的 MVC 应用程序的服务层中,我尝试将 linq to sql 实体结果转换为我的业务模型实体。我目前正在尝试以下代码: public IList GetAllProjects()
我正在开发一个允许俱乐部成员(member)注册的网站。表单中的信息应该存储到 MySQL 数据库中。我已经通过存储和读取 XML 样式文本文件来完成此任务,但现在我必须将其转换为 MySQL。以下是
我的应用程序有一个 Java servlet,它从请求中读取 JSONObject 并构造一些在其他地方使用的 Java 对象。我遇到了一个问题,因为 JSON 中的字符串是用 ISO-8859-1
我是一名优秀的程序员,十分优秀!