gpt4 book ai didi

ios - 在 IOS 中,在 "Edit Mode"中,如何将带有单元格的新部分添加到静态 UITableView?

转载 作者:行者123 更新时间:2023-11-28 13:20:29 25 4
gpt4 key购买 nike

看来我在试图解决这个问题时遇到了死胡同。

我正在开发一个包含静态 UITableView 的应用程序,该 UITableView 包含 3 个部分,每个部分包含一个单元格。每个单元格都包含一个 UITextField。在导航栏上,我有一个编辑按钮,单击后将启用 UITextFields——允许用户修改文本。

我想知道是否有人可以指导我正确的方向。我想用一个单元格添加一个额外的部分,其中包含一个“删除”按钮。

对于我正在尝试做的事情,我能找到的最好的例子是在联系人应用程序中。注意这里,没有删除按钮。 Regular view, no delete button

启用编辑模式后,将添加一个带有单元格的额外部分,其中包含一个删除按钮。 edit mode, delete button appears

我已经通过覆盖 setEditing 方法来设置代码以启用编辑模式。

override func setEditing(editing: Bool, animated: Bool) {

super.setEditing(editing, animated: animated)

if editing {
// enable textfields
}
else {
// disable textfields
// save data
}

提前致谢! :)

最佳答案

当您启用或禁用编辑时,重新加载您的 TableView :

self.tableView!.reloadData()

从那里,您可以返回一些不同的值,具体取决于您是否正在编辑。下面是一些示例:

func numberOfSectionsInTableView(tableView: UITableView) -> Int {

var sectionCount = 1
if tableView.editing {

sectionCount += 1

}
return sectionCount

}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

let lastSection = 1
if section == lastSection {

return 1

}
return 5

}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let lastSection = 1
if (indexPath.section == lastSection) {

// return the special delete cell

} else {

// return other cells

}

}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

let lastSection = 1
if (indexPath.section == lastSection) {

// handle delete cell

} else {

// handle other cells

}

}

关于ios - 在 IOS 中,在 "Edit Mode"中,如何将带有单元格的新部分添加到静态 UITableView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26346098/

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