简体   繁体   English

滑动删除时如何使tableViewCell不展开

[英]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]

}

Before swipe to delete 滑动删除之前

After swipe to delete 滑动删除后

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.

相关问题 滑动删除时隐藏TableViewCell中的标签 - Hide label in TableViewCell when swipe to delete 滑动删除无法在TableVIewCell上运行? - Swipe delete not working on TableVIewCell? ios滑动tableviewcell删除有时可以工作 - ios swipe tableviewcell to delete sometimes working 滑动以删除破坏tableviewcell功能的选项 - swipe to delete option breaking the tableviewcell functionality 如何在Swift 2中的另一个ViewController中滑动删除Core Data TableViewCell(带行动作) - How to swipe to delete Core Data TableViewCell (with row action) in another ViewController in Swift 2 Swift-如果检测到“滑动删除”,如何在自定义tableViewCell类中隐藏按钮? - Swift - How to hide button in custom tableViewCell class if left “Swipe to delete” detected? 如何自动滑动/滑动单元格tableviewcell swift 3 - how to automatically slide/swipe the cell tableviewcell swift 3 在UItableview中如何动态展开和折叠特定的TableviewCell - In UItableview How to Expand and collapse particular TableviewCell dynamically 当tableView的allowsMultipleSelectionDuringEditing属性为YES时,如何进行滑动到删除工作? - How do I get swipe-to-delete working when tableView's allowsMultipleSelectionDuringEditing property is YES? 如何在特定TableViewCell上方(或下方)获取TableViewCell - How to get the TableViewCell above (or below) a specific TableViewCell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM