iPhone UI 设计问题 - 设计表单的最佳方式?

发布于 2024-09-10 16:26:29 字数 246 浏览 3 评论 0原文

我想设计一个应用程序,需要用户输入一些内容,例如开始日期、结束日期、一堆其他选项和一些文本注释,我计划使用选择器来选择将以模式方式向上滑动的数据。我需要上下移动视图,以确保当选择器和键盘上下滑动时,填充的元素保持焦点。

我的问题是实施这种“形式”的最佳视图是什么?我正在考虑分组表视图,我可以在其中将字段部分分开。

还有其他方法可以实现这些事情吗? 根据经验或最佳实践,是否有更好的替代方案或示例代码或应用程序可供我探索?

开发。

I want to design an app that needs user to input few things like start date, end date, bunch of other options and some text comments for which I am planning to use pickers to select the data that will slide up modally. I will need to move the view up and down to make sure that the element being filled stays in focus when the pickers and keyboard slides up and down.

My question is what would be the best view to implement such a "form"? I was thinking grouped table view where I could separate the fields section wise.

Is there any other way to implement these things?
By experience or best practices, are there any better alternatives or sample code or apps out there that I can explore?

Dev.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江心雾 2024-09-17 16:26:29

最像 iPhone 的表单界面是分组表格视图。这是大多数用户在使用其他使用分组表视图来添加和编辑结构化数据的应用程序后所期望的。

一个好的做法是为节和节内的行创建一个enum(枚举),例如:

typedef enum {
    kFormSectionFirstSection = 0,
    kFormSectionSecondSection,
    kFormSectionThirdSection,
    kFormSections
} FormSection;

typedef enum {
    kFormFirstSectionFirstRow = 0,
    kFormFirstSectionSecondRow,
    kFormFirstSectionRows
} FormFirstSectionRow;

...

在本示例中,您可以使用此枚举按名称而不是编号来引用节。

(实际上,您可能不会使用 kFormSectionFirstSection 作为描述性名称,而是使用 kFormSectionNameFieldSectionkFormSectionAddressFieldSection 等,但这应该是希望的说明枚举的结构。)

您将如何使用它?

下面是一些表视图委托方法的示例,演示了它的用途:

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    return kFormSections;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch (section) {
        case kFormSectionFirstSection:
            return kFormFirstSectionRows;

        case kFormSectionSectionSection:
            return kFormSecondSectionRows;

        ...

        default:
            break;
    }
    return -1;
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    // cell setup or dequeue...

    switch (indexPath.section) {
        case kFormSectionThirdSection: { 
            switch (indexPath.row) {
                case kFormThirdSectionFourthRow: {

                    // do something special here with configuring 
                    // the cell in the third section and fourth row...

                    break;
                }

                default:
                    break;
            }
        }

        default:
            break;
    }

    return cell;
}

这应该快速显示枚举的实用性和强大功能。

代码中的名称比数字更容易阅读。当您处理委托方法时,如果您对节或行有一个很好的描述性名称,则可以更轻松地阅读表视图和单元格的管理逻辑。

如果您想更改部分或行的顺序,您所要做的就是重新排列 enum 构造中枚举标签的顺序。您不需要进入所有委托方法并更改幻数,一旦你有超过几个部分和行,这很快就会变成一种棘手且容易出错的舞蹈。

The most iPhone-like interface for forms is going to be a grouped table view. It is what most users will expect, after using other apps which use grouped table views for adding and editing structured data.

A good practice is to create an enum (enumeration) for sections and for rows within sections, e.g.:

typedef enum {
    kFormSectionFirstSection = 0,
    kFormSectionSecondSection,
    kFormSectionThirdSection,
    kFormSections
} FormSection;

typedef enum {
    kFormFirstSectionFirstRow = 0,
    kFormFirstSectionSecondRow,
    kFormFirstSectionRows
} FormFirstSectionRow;

...

In this example, you can use this enumeration to refer to sections by name instead of number.

(In practice, you probably wouldn't use kFormSectionFirstSection as a descriptive name, but something like kFormSectionNameFieldSection or kFormSectionAddressFieldSection etc., but this should hopefully illustrate the structure of the enum.)

How would you use this?

Here's an example of a few table view delegate methods which demonstrate how this is useful:

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    return kFormSections;
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch (section) {
        case kFormSectionFirstSection:
            return kFormFirstSectionRows;

        case kFormSectionSectionSection:
            return kFormSecondSectionRows;

        ...

        default:
            break;
    }
    return -1;
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    // cell setup or dequeue...

    switch (indexPath.section) {
        case kFormSectionThirdSection: { 
            switch (indexPath.row) {
                case kFormThirdSectionFourthRow: {

                    // do something special here with configuring 
                    // the cell in the third section and fourth row...

                    break;
                }

                default:
                    break;
            }
        }

        default:
            break;
    }

    return cell;
}

This should quickly show the utility and power of enumerations.

Names in code are much easier to read than numbers. When you're dealing with delegate methods, if you have a good descriptive name for a section or a row, you can more easily read the logic of how the table view and cells are managed.

If you want to change the order of sections or row, all you have to do is rearrange the order of enumerated labels in the enum construct. You wouldn't need to go into all the delegate methods and change magic numbers, which quickly becomes a tricky and error-prone dance once you have more than a couple sections and rows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文