[英]How to get the tableViewCell not to expand when swipe to delete
I have my app set up so that I can add a cell to a ViewController where the cell appears in the tableView but when you click on the cell it expands to show more information. 我已经设置好我的应用程序,以便可以将一个单元格添加到ViewController中,该单元格将出现在tableView中,但是当您单击该单元格时,它将展开以显示更多信息。 Here is the code...
这是代码...
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var selectedIndexPath: NSIndexPath? = nil
override func viewDidLoad() {
super.viewDidLoad()
tableView.registerNib(UINib(nibName: "CustomViewCell", bundle: nil), forCellReuseIdentifier: "Cell")
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CustomViewCell
cell.clipsToBounds = true
return cell
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if selectedIndexPath != nil {
if indexPath == selectedIndexPath {
return 140
} else {
return 38
}
} else {
return 38
}
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
// New
switch selectedIndexPath {
case nil:
selectedIndexPath = indexPath
default:
if selectedIndexPath! == indexPath {
selectedIndexPath = nil
} else {
selectedIndexPath = indexPath
}
}
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
}
Everything works fine with the expanding and closing for the cell except that I configured the cell to swipe to delete but the cell just expands when I swipe to delete. 除了将单元格配置为滑动以删除外,其他一切都可以通过该单元格的扩展和关闭而正常进行,但是当我滑动以删除时,该单元格才可以扩展。 Heres the code:
这是代码:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete") { (action , indexPath ) -> Void in
self.editing = false
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let moc = appDelegate.managedObjectContext
moc.deleteObject(self.events[indexPath.row])
appDelegate.saveContext()
self.events.removeAtIndex(indexPath.row)
tableView.reloadData()
}
return [deleteAction]
}
I dont want the the cell to expand like it is when I swipe to delete, Any ideas? 我不希望该单元格像我滑动删除时那样展开,有什么想法吗?
I think you may be the one who is expanding the cell. 我认为您可能是扩展牢房的人。 You are saying:
你是说:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath == selectedIndexPath {
return 140
}
}
Is that method being called during swipe to delete? 在刷卡删除期间是否调用了该方法? Use debugging to find out.
使用调试找出。 If it is, you'll need to rewrite that code so that, just in case you're in the middle of swipe to delete, you don't return 140.
如果是这样,您将需要重写该代码,以防万一您要滑动要删除,而不会返回140。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.