gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 19:35:31 25 4
gpt4 key购买 nike

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

我的问题是实现这种“表单”的最佳 View 是什么?我正在考虑分组 TableView ,我可以在其中明智地分隔字段。

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

开发

最佳答案

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

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

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

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

...

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

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

你会如何使用这个?

下面是一些 TableView 委托(delegate)方法的示例,演示了它的用途:

- (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;
}

这应该很快就能显示出枚举的实用性和威力。

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

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

关于iPhone UI 设计问题 - 设计表单的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3302626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com