我有一个表格视图控制器,我嵌入了一个左栏编辑项目按钮。
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.leftBarButtonItem = self.editButtonItem
}
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if (editingStyle == UITableViewCellEditingStyle.delete) {
MessageTableView.deleteRows(at: [indexPath], with: .fade)
}
}
但是我遵循的每一个教程,我得到的第一张照片都是我想要的。
答案 0 :(得分:2)
根据您在问题下方的评论,您已为表格视图启用了allowsMultipleSelectionDuringEditing
属性。启用此选项后,表格在编辑表格视图时支持多项选择。这优先于支持“正常”编辑功能,例如删除。这就是为什么你得到复选框(用于选择)而不是红色删除圈。
如果您想在编辑模式下支持使用红色圆圈删除单元格,则需要在编辑期间禁用多个选择。
答案 1 :(得分:0)
var arrayDays:[Student] = []
@IBOutlet var tableViewForStudents: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let std1 = Student(name: "First", rollNo: 1, address: "this is \\n address of \\n student 1",image:"demo.png")
let std2 = Student(name: "Two", rollNo: 2, address: "this is \\n address of \\n student 2",image:"demo.png")
let std3 = Student(name: "Three", rollNo: 3, address: "this is \\n address of \\n student 3",image:"demo.png")
let std4 = Student(name: "Four", rollNo: 4, address: "this is \\n address of \\n student 4",image:"demo.png")
let std5 = Student(name: "Five", rollNo: 5, address: "this is \\n address of \\n student 5",image:"demo.png")
let std6 = Student(name: "Six", rollNo: 6, address: "this is \\n address of \\n student 6",image:"demo.png")
arrayDays.append(std1)
arrayDays.append(std2)
arrayDays.append(std3)
arrayDays.append(std4)
arrayDays.append(std5)
arrayDays.append(std6)
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
arrayDays.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .left)
}
导入UIKit
class Student: NSObject {
var strStudentName:String!
var strStrudentRollNo:Int!
var strStudentAddress:String!
var imageName:String!
init(name:String, rollNo:Int, address:String,image:String) {
strStudentName = name
strStrudentRollNo = rollNo
strStudentAddress = address
imageName = image
}
}