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

Dev*_*Dev 3 forms iphone modalpopups uitableview

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

我的问题是,实施这种"形式"的最佳观点是什么?我在想分组表视图,在那里我可以将字段分开.

有没有其他方法来实现这些东西?根据经验或最佳实践,我可以探索哪些更好的替代品或示例代码或应用程序?

开发.

Ale*_*lds 7

表单的类似iPhone的界面将是一个分组的表视图.在使用其他使用分组表视图添加和编辑结构化数据的应用程序之后,这是大多数用户所期望的.

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

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

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

...
Run Code Online (Sandbox Code Playgroud)

在此示例中,您可以使用此枚举按名称而不是数字来引用节.

(在实践中,你可能不会使用kFormSectionFirstSection作为一个描述性的名称,但类似kFormSectionNameFieldSectionkFormSectionAddressFieldSection等,但这应该有希望说明的结构enum.)

你会怎么用这个?

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

- (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;
}
Run Code Online (Sandbox Code Playgroud)

这应该很快显示枚举的效用和功效.

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

如果要更改节或行的顺序,您只需重新排列enum构造中枚举标签的顺序.您不需要进入所有委托方法并更改幻数,一旦您有多个部分和行,这很快就会成为一个棘手且容易出错的舞蹈.