Swift-如何在没有segue的情况下在tableview中选择多行
我的开发环境是swift3,xcode8。 我正在制作一个类似苹果信息应用程序的列表应用程序。 当我在表视图中选择列表时,我会转到详细信息页面(通过seg),现在我想实现多个删除功能,但出现了一个问题。在编辑模式下,我可以看到选择窗口,但如果选择该选择窗口,只需转到详细信息页面Swift-如何在没有segue的情况下在tableview中选择多行,swift,tableview,Swift,Tableview,我的开发环境是swift3,xcode8。 我正在制作一个类似苹果信息应用程序的列表应用程序。 当我在表视图中选择列表时,我会转到详细信息页面(通过seg),现在我想实现多个删除功能,但出现了一个问题。在编辑模式下,我可以看到选择窗口,但如果选择该选择窗口,只需转到详细信息页面 也许在通过Seg进入详细页面之前。我想我应该选择多项选择。我该怎么办?确保您符合以下代码 class TableviewController:UITableViewController{ override func vi
也许在通过Seg进入详细页面之前。我想我应该选择多项选择。我该怎么办?确保您符合以下代码
class TableviewController:UITableViewController{
override func viewDidLoad() {
super.viewDidLoad()
var isMultipleSelectionActive = false
var selectedItems: [String: Bool] = [:]
tableView.allowsMultipleSelectionDuringEditing = true
tableView.setEditing(true, animated: false)
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.textLabel?.text = "\(indexPath.row)"
return cell
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let selectedItem = items.objectAtIndex(indexPath.row)
//add to selectedItems
selectedItems[selectedItem] = true
}
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
let selectedItem = items.objectAtIndex(indexPath.row)
// remove from selectedItems
selectedItems[selectedItem] = nil
}
func getStatusOfSelectedItems() {
for item in selectedItems {
println(item)
}
}
//You should override shouldPerformSegueWithIdentifier and return false if isMultipleSelectionActive is true
override func shouldPerformSegue(withIdentifier identifier: String?, sender: Any?) -> Bool {
if let identifierName = identifier {
if identifierName == "NameOfYourSegueIdentifier" {
if isMultipleSelectionActive {
return false
}
}
}
return true
}
}
此代码用于选择多行
class TableViewController: UITableViewController
{
var lastSelectedIndexPath = NSIndexPath(forRow: -1, inSection: 0)
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath)
// Configure the cell...
cell.textLabel!.text = "row: \(indexPath.row)"
if cell.selected
{
cell.selected = false
if cell.accessoryType == UITableViewCellAccessoryType.None
{
cell.accessoryType = UITableViewCellAccessoryType.Checkmark
}
else
{
cell.accessoryType = UITableViewCellAccessoryType.None
}
}
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
let cell = tableView.cellForRowAtIndexPath(indexPath)
if cell!.selected
{
cell!.selected = false
if cell!.accessoryType == UITableViewCellAccessoryType.None
{
cell!.accessoryType = UITableViewCellAccessoryType.Checkmark
}
else
{
cell!.accessoryType = UITableViewCellAccessoryType.None
}
}
}
谢谢你的回复。但我的问题是,如果我在编辑模式下检查,它不会被检查,而是通过单元格的segue操作转到详细信息页面。我想检查它在编辑状态,而不是segue操作,如果我编译没有segue多选工作良好。谢谢你的答复。但是,这段代码没有找到我需要的源代码。只有当segue不工作时,多重选择才能正常工作。有没有办法不在编辑模式下的多选模式下进入segue?我如何向您显示我的代码?我不太清楚,因为我是初学者。。通过使用control+鼠标左键从情节提要中拖动单元格,将其拖动到详细信息页面,然后选择show.Cool!!我明白了,我想你可能已经为它写了代码@HoonyB@HoonyB确保根据需要更新isMultipleSelectionActive变量!!谢谢你,兄弟。我解决了这个问题!对不起,我没有看到酱汁的底部。我想知道的是这个函数。