iPhone联系人应用程序';s";“联系人视图/编辑视图”;XCODE

iPhone联系人应用程序';s";“联系人视图/编辑视图”;XCODE,iphone,objective-c,xcode,cocoa-touch,Iphone,Objective C,Xcode,Cocoa Touch,实际上,我正在制作一个应用程序,其中有一个表视图(列出所有课程) 单击其中一个按钮将显示该课程的详细信息。(详细视图) 现在我要做的是,详细视图的编辑模式。。 我想给它一种iphone原生应用的感觉:P 当我查看联系人的应用程序时,当我在联系人中单击“编辑”时,它似乎不会改变整个视图控制器,而只是隐藏/显示旧/新字段和按钮 如果它不是一个新的视图控制器(用于编辑),那么它到底是如何工作的? 如果它是一个新的视图控制器,那么我想,它相当简单,将视图控制器推入导航堆栈。在视图控制器的“-(void)

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

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

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

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

 - (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.
}
现在,当视图控制器(和表视图)进入编辑模式时,视图控制器会告诉表在编辑点插入行。表格本身也会进入编辑模式

- (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.
}
随着视图控制器移出编辑(及其表格视图),编辑特定的行将被删除

请注意,如果您使用的不是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.
}

是的,您正在编写iPhone中的native contact应用程序,它不会更改整个视图控制器,只会隐藏/显示旧/新字段和按钮

为此,首先您必须获取UITableView,然后您可以通过获取不同的节和该节中的行来添加视图,或者使用UITableView的标题视图来添加视图 在联系人的应用程序联系人的图像视图中显示一些视图,如联系人的应用程序,在UITableView的标题视图中显示联系人姓名和公司字段

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

这样,您可以显示由用户选择的课程的详细视图

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

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

当用户点击显示课程详细信息的下一个视图中的特定课程负载时

当用户点击编辑按钮时,删除课程详情表表单视图,例如[tableview removeFromSuperView]

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


e、 g[self.view addSubview:courseEditTable]

好吧,我明白了。但是单元格标签怎么变成文本字段呢?他们也会在那个位置重新加载单元格。阅读我对上述代码的修改,了解它们是如何一起发生的。好的,beginUpdate和endUpdate修复了这个问题。。另外,我使用自定义单元格视图显示文本字段而不是标签,并在setEditing函数上设置其“enabled”属性。。