iPhone Contact App的“联系人视图/编辑视图”XCODE

时间:2012-07-24 10:02:46

标签: iphone objective-c xcode cocoa-touch

我实际上正在制作一个有桌面视图的应用程序(列出所有课程) 单击其中一个将显示该课程的详细信息。 (详细视图) 现在我要做的是,该详细视图的编辑模式.. 我想让它感觉像iphone的原生应用程序:P

当我查看联系人的应用程序时,当我点击联系人中的“编辑”时,它似乎没有更改整个视图控制器,只是隐藏/显示旧/新字段和按钮..

如果它不是一个新的视图控制器(用于编辑),那么它是如何工作的呢? 如果它是一个新的视图控制器,那么我猜,它非常简单,将视图控制器推入导航堆栈。

2 个答案:

答案 0 :(得分:1)

在视图控制器的“ - (void)setEditing:(BOOL)编辑动画:(BOOL)动画”方法中,覆盖当前行为:

 - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [self.tableView beginUpdates]; // Tell the table to begin updates to ensure that the following reloads and animations all happen at once

    [super setEditing:editing animated:animated];

    // set the table editing if you are not using UITableViewController

    // reload any rows that may need updating for the new state

    if (editing) {
        // tell the table view to insert the editing rows
    } else {
        // tell the table view to remove the editing rows
    }

    [self.tableView endUpdates]; // commit the updates.
}

现在,当视图控制器(和表视图)进入编辑模式时,视图控制器告诉表在编辑点插入行。表本身也进入编辑模式。

当视图控制器退出编辑(以及带有它的表视图)时,将删除特定于编辑的行。

请注意,如果您没有使用UITableViewController子类,而只是UIViewController本身的子类,则需要告诉表视图同时进入编辑状态:

[tableView setEditing:editing animated:animated];

如果需要重新加载或插入行等,委托和数据源方法需要检查表是否处于编辑模式,并返回编辑或非编辑模式所需的行。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView.editing) {
        return /*editing count*/;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView.editing) {
        // return cells for the editing state.
    }

    // return cells based on the standard state.
}

答案 1 :(得分:0)

是的,您在iPhone中编写本机联系人的应用程序并不会更改整个视图控制器,而只是隐藏/显示旧/新字段和按钮..

为此目的首先你必须使用UITableView然后你可以通过采取不同的部分然后在该部分中的行或使用UITableView的标题视图来添加您的视图 在联系人的应用程序中显示联系人应用程序的一些视图联系人的ImageView和联系人姓名和公司字段显示在UITableView的标题视图中。

您还可以使用UITableView的页脚视图在表格视图底部添加按钮或部分视图。

像这样你可以显示用户选择的课程的详细视图。

对于编辑模式,当用户点击“编辑”按钮时,您需要重新加载表格视图并在表格视图的委托方法中为表格视图提供适当的视图,为此您需要跟踪模式,即课程详细信息视图模式或课程编辑模式。

OR

对于两种不同的模式,您可以使用两个单独的表格。

当用户点击特定课程加载下一个显示课程详情的视图时,

当用户点击“编辑”按钮时,删除课程详细信息表格形式视图,例如[tableview removeFromSuperView];

并添加具有不同视图的课程编辑表,

例如[self.view addSubview:courseEditTable];