在iOS中实现表单的最佳实践是什么?

时间:2023-01-19 20:07:07

I need to create several screens-forms that would be used for entering data and posting to the server. I have not done that kind of stuff yet, so I'm just wondering are there any best practices for doing that. Currently, I would just drop several text fields, radios and etc, do some manual input validation, do an assembly of input data into URL and then do submission to the server.

我需要创建几个屏幕表单,用于输入数据和发布到服务器。我还没有做过这样的事情,所以我只是想知道有没有做到这一点的最佳实践。目前,我只需删除几个文本字段,无线电等,进行一些手动输入验证,将输入数据汇编到URL中,然后提交到服务器。

I'm thinking about usability, so I think I should implement "move to next text field" after a user dismisses keyboard (resigns first responder). But if all the inputs are filled already and a user changes the value of one field then just navigate to submit button. So, IMHO that might be an example of practice for implementing a form. What practices do you apply?

我正在考虑可用性,所以我认为在用户解除键盘(辞职第一响应者)后我应该实现“移动到下一个文本字段”。但是如果已经填充了所有输入并且用户更改了一个字段的值,则只需导航到提交按钮。所以,恕我直言,这可能是实施表格的一个实践的例子。你适用什么做法?

2 个解决方案

#1


34  

A few of my experiences from implementing forms:

我实施表格的一些经验:

  • Place inputs and labels in the rows of a UITableView (grouped). It's the way Apple does it and the way most users are used to. But be wary with the reuse of cells, as this may cause your inputs to move around otherwise. In other words, keep references to your inputs in a separate NSArray (or NSDictionary) to make sure they're not lost when the UITableViewCells are reused.

    将输入和标签放在UITableView(已分组)的行中。这就是Apple的方式以及大多数用户习惯的方式。但要小心重复使用单元格,因为这可能会导致您的输入以其他方式移动。换句话说,在单独的NSArray(或NSDictionary)中保持对输入的引用,以确保在重用UITableViewCell时它们不会丢失。

  • Using the keyboard return key to move to the next input is a good idea. It's easy to do if you just keep track of which table cell you're editing, so you can move on to the next one using its NSIndexPath.

    使用键盘返回键移动到下一个输入是一个好主意。如果您只是跟踪正在编辑的表格单元格,那么很容易做到,因此您可以使用其NSIndexPath继续下一个表格单元格。

  • Check your form validity when the user's made modifications, i.e. by listening to UITextFieldTextDidChangeNotification and in textFieldShouldEndEditing:. If the form's valid, allow the user to submit it on return or using a Done button (or similar).

    在用户进行修改时检查您的表单有效性,即通过监听UITextFieldTextDidChangeNotification和textFieldShouldEndEditing :.如果表单有效,则允许用户在返回时使用提交或使用“完成”按钮(或类似)。

  • If the user's editing the last row in the form, change the keyboard return button type to Done or similar.

    如果用户正在编辑表单中的最后一行,请将键盘返回按钮类型更改为“完成”或类似。

  • UPDATE: Since posting this, it's also become quite common to show input accessory views (the toolbar with Prev/Next/Done) on top of the keyboard. In particular when you've got a more extensive form where users might want to go back and forth between inputs. And it's quite easy to implement.

    更新:自发布此内容以来,在键盘顶部显示输入附件视图(带有上一个/下一个/完成的工具栏)也变得非常普遍。特别是当你有一个更广泛的形式,用户可能希望在输入之间来回切换。而且它很容易实现。

Hope that helps!

希望有所帮助!

#2


2  

in my application there are also several forms and i have used all field manually and for validation i created validation function for that .we have to pass this value and check it .if your forms have same field than you can create UiView for that and used that view in all screen. but i will be generted problem at checking and validation time..

在我的应用程序中,还有几种形式,我手动使用所有字段,并为验证我创建验证功能。我们必须传递此值并检查它。如果您的表单具有相同的字段,您可以创建UiView并使用它所有屏幕中的视图。但我会在检查和验证时间产生问题..

so it is better way to do manually drag and drop all field and make common function for validation. for ResignFirstResponder you have to check all field that no one field is emplty than you can redirect to next page .i have no idea any inbuilt functionality for that .

因此,更好的方法是手动拖放所有字段并为验证提供通用功能。对于ResignFirstResponder,你必须检查所有字段,没有一个字段是空的,你可以重定向到下一页。我不知道任何内置的功能。

i hope this will help you.

我希望这能帮到您。

#1


34  

A few of my experiences from implementing forms:

我实施表格的一些经验:

  • Place inputs and labels in the rows of a UITableView (grouped). It's the way Apple does it and the way most users are used to. But be wary with the reuse of cells, as this may cause your inputs to move around otherwise. In other words, keep references to your inputs in a separate NSArray (or NSDictionary) to make sure they're not lost when the UITableViewCells are reused.

    将输入和标签放在UITableView(已分组)的行中。这就是Apple的方式以及大多数用户习惯的方式。但要小心重复使用单元格,因为这可能会导致您的输入以其他方式移动。换句话说,在单独的NSArray(或NSDictionary)中保持对输入的引用,以确保在重用UITableViewCell时它们不会丢失。

  • Using the keyboard return key to move to the next input is a good idea. It's easy to do if you just keep track of which table cell you're editing, so you can move on to the next one using its NSIndexPath.

    使用键盘返回键移动到下一个输入是一个好主意。如果您只是跟踪正在编辑的表格单元格,那么很容易做到,因此您可以使用其NSIndexPath继续下一个表格单元格。

  • Check your form validity when the user's made modifications, i.e. by listening to UITextFieldTextDidChangeNotification and in textFieldShouldEndEditing:. If the form's valid, allow the user to submit it on return or using a Done button (or similar).

    在用户进行修改时检查您的表单有效性,即通过监听UITextFieldTextDidChangeNotification和textFieldShouldEndEditing :.如果表单有效,则允许用户在返回时使用提交或使用“完成”按钮(或类似)。

  • If the user's editing the last row in the form, change the keyboard return button type to Done or similar.

    如果用户正在编辑表单中的最后一行,请将键盘返回按钮类型更改为“完成”或类似。

  • UPDATE: Since posting this, it's also become quite common to show input accessory views (the toolbar with Prev/Next/Done) on top of the keyboard. In particular when you've got a more extensive form where users might want to go back and forth between inputs. And it's quite easy to implement.

    更新:自发布此内容以来,在键盘顶部显示输入附件视图(带有上一个/下一个/完成的工具栏)也变得非常普遍。特别是当你有一个更广泛的形式,用户可能希望在输入之间来回切换。而且它很容易实现。

Hope that helps!

希望有所帮助!

#2


2  

in my application there are also several forms and i have used all field manually and for validation i created validation function for that .we have to pass this value and check it .if your forms have same field than you can create UiView for that and used that view in all screen. but i will be generted problem at checking and validation time..

在我的应用程序中,还有几种形式,我手动使用所有字段,并为验证我创建验证功能。我们必须传递此值并检查它。如果您的表单具有相同的字段,您可以创建UiView并使用它所有屏幕中的视图。但我会在检查和验证时间产生问题..

so it is better way to do manually drag and drop all field and make common function for validation. for ResignFirstResponder you have to check all field that no one field is emplty than you can redirect to next page .i have no idea any inbuilt functionality for that .

因此,更好的方法是手动拖放所有字段并为验证提供通用功能。对于ResignFirstResponder,你必须检查所有字段,没有一个字段是空的,你可以重定向到下一页。我不知道任何内置的功能。

i hope this will help you.

我希望这能帮到您。