多重选择在IOS中无法正常工作 [英] Multi select is not working properly in IOS
问题描述
我在iOS表格视图中为行设置复选标记时遇到问题 如果我在上方选择了一个元素,那么下一个第13个元素也会被选中,我不确定为什么吗?
I have a problem with setting the checkmark for a row in iOS table view If I select one element above, the next 13th element is also getting selected, I not sure why?
在设置复选标记之前,我必须对表做些什么,因为我只是在检查一个条件,如果该条件为真,则将附件类型设置为复选标记,下面是代码.
Should I have to do something with the table before setting the checkmark, cause I am just checking one condition and if that condition is true I am setting the accessoryType as checkmark, below is the code.
注意:-发生这种情况时,第13行将不会被选中,它只会更改该行的附件类型.
Note:- When this happen the 13th row will not get selected, it just changes the accessory type of that row.
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
if cell.selected {
if(self.sections[indexPath.section].files[indexPath.row].type != "cloud"){
print(self.sections[indexPath.section].files[indexPath.row])
cell.accessoryType = .Checkmark
NSNotificationCenter.defaultCenter().postNotificationName("enableOptions", object: nil)
}
}
}
CellForIndexPath代码:
CellForIndexPath Code:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! MyFilesTableViewCell
let fileSection = sections[indexPath.section]
let file = fileSection.files[indexPath.row]
cell.title.text = file.name
if file.timeStamp.isEmpty{
cell.timeStamp.hidden = true
}else{
cell.timeStamp.hidden = false
cell.timeStamp.text = file.timeStamp
}
cell.icon.image = file.icon
cell.actionsBtn.row = indexPath.row
cell.actionsBtn.section = indexPath.section
cell.actionsBtn.setTitle("\u{f142}", forState: .Normal)
cell.actionsBtn.addTarget(self, action: #selector(MyFilesTableViewController.buttonClicked(_:)), forControlEvents: UIControlEvents.TouchUpInside)
if(editingTable){
cell.actionsBtn.hidden = true
}else{
cell.actionsBtn.hidden = false
}
if(file.type == "cloud"){
cell.actionsBtn.hidden = true
}
cell.progressBar.progress = 0.0
cell.progressBar.hidden = true
return cell
}
推荐答案
您的单元格在cellForRowAtIndexPath中可重用的问题.请使用下面的代码.
Its problem with your cell reusable in cellForRowAtIndexPath. Kindly use the below code.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! MyFilesTableViewCell
cell.accessoryType = .None
if cell.selected {
if(self.sections[indexPath.section].files[indexPath.row].type != "cloud"){
print(self.sections[indexPath.section].files[indexPath.row])
cell.accessoryType = .Checkmark
}
}
let fileSection = sections[indexPath.section]
let file = fileSection.files[indexPath.row]
cell.title.text = file.name
if file.timeStamp.isEmpty{
cell.timeStamp.hidden = true
}else{
cell.timeStamp.hidden = false
cell.timeStamp.text = file.timeStamp
}
cell.icon.image = file.icon
cell.actionsBtn.row = indexPath.row
cell.actionsBtn.section = indexPath.section
cell.actionsBtn.setTitle("\u{f142}", forState: .Normal)
cell.actionsBtn.addTarget(self, action: #selector(MyFilesTableViewController.buttonClicked(_:)), forControlEvents: UIControlEvents.TouchUpInside)
if(editingTable){
cell.actionsBtn.hidden = true
}else{
cell.actionsBtn.hidden = false
}
if(file.type == "cloud"){
cell.actionsBtn.hidden = true
}
cell.progressBar.progress = 0.0
cell.progressBar.hidden = true
return cell
}
这篇关于多重选择在IOS中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!