iPhone 联系人应用程序的 "Contact View/Edit View"XCODE

标签 iphone objective-c xcode cocoa-touch

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

当我查看联系人的应用程序时,当我在联系人中单击“编辑”时,它似乎并没有更改整个 View Controller ,而只是隐藏/显示旧/新字段和按钮。

如果它不是一个新的 View Controller (用于编辑),那么它到底是如何工作的? 如果它是一个新的 View Controller ,那么我想,它非常简单,将 View Controller 插入导航堆栈..

最佳答案

在 View Controller 的“-(void)setEditing:(BOOL)editinganimated:(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.
}

现在,当 View Controller (和 TableView )进入编辑模式时, View Controller 告诉表在编辑点插入行。表格本身也进入编辑模式。

当 View Controller 退出编辑(以及包含它的表格 View )时,正在编辑的特定行将被删除。

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

[tableView setEditing:editing animated:animated];

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

- (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 联系人应用程序的 "Contact View/Edit View"XCODE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11628500/

相关文章:

objective-c - 为 CoreAudio 设置效果音频单元

ios - 从 iOS Xcode 5 中的数组列表中一一显示字符串

iphone - UILabel 超出应用程序框架

objective-c - 使用 Xcode 4 的 TableView 快速多点触控

iphone - 在sqlite数据库中插入大量数据需要很长时间

iphone - 如何控制分组表格 View 单元格中图像的位置?

objective-c - iOS-如何在线程(使用GCD)结束工作时收到通知

iPhone applicationWillResignActive - 如何通知当前UIView

iphone - 应用商店中的 A/B 测试 View ?

ios - 在固定页脚的 UIView 中向页脚添加按钮