首页 > 解决方案 > swift中tableview单元格滑动图标之间的空间

问题描述

在我的代码中,当我滑动 tableview 单元格时,图标看起来像是彼此重叠。但我想要这些图标之间的一些空间。我的代码:-

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?{
        let inboxAction =  UIContextualAction(style: .normal, title: "", handler: { (action,view,completionHandler ) in
            //do stuff
            let storyboard = UIStoryboard(name: "Swipe", bundle: nil)
            let selectParentProfile = storyboard.instantiateViewController(withIdentifier: "InboxViewController") as? InboxViewController
            self.navigationController?.pushViewController(selectParentProfile!, animated: true)
            completionHandler(true)
        })
        // create action for the delete button
        let cgImageXq = UIGraphicsImageRenderer(size: CGSize(width: 110, height: 120)).image { _ in
            UIImage(named: "inbox")?.draw(in: CGRect(x: 0, y: 0, width: 110, height: 120))
        }
        inboxAction.image = cgImageXq
        //create action for the block button
        let filesAction =  UIContextualAction(style: .normal, title: "", handler: { (action,view,completionHandler ) in
            //do stuff
            let storyboard = UIStoryboard(name: "Swipe", bundle: nil)
            let selectParentProfile = storyboard.instantiateViewController(withIdentifier: "PdfFilesViewController") as? PdfFilesViewController
            self.navigationController?.pushViewController(selectParentProfile!, animated: true)
            
            completionHandler(true)
        })
        let cgImageY = UIGraphicsImageRenderer(size: CGSize(width: 100, height: 120)).image { _ in
            UIImage(named: "eval-form")?.draw(in: CGRect(x: 0, y: 0, width: 100, height: 120))
        }
        filesAction.image = cgImageY
        //create action for the block button
        let browserAction =  UIContextualAction(style: .normal, title: "", handler: { (action,view,completionHandler ) in
            //do stuff
            let storyBoard = UIStoryboard(name: "Form", bundle: nil)
            let folderTableViewController = storyBoard.instantiateViewController(identifier: "FormForPdfViewController")
            
            self.navigationController?.pushViewController(folderTableViewController, animated: true)
            
        })
        let cgImageZ = UIGraphicsImageRenderer(size: CGSize(width: 100, height: 120)).image { _ in
            UIImage(named: "pdf-files")?.draw(in: CGRect(x: 0, y: 0, width: 100, height: 120))
        }
        browserAction.image = cgImageZ
        // Add both the delete button and add button here
        let confrigation = UISwipeActionsConfiguration(actions: [browserAction, filesAction, inboxAction])
        confrigation.performsFirstActionWithFullSwipe = false
        return confrigation
    }

在此处输入图像描述

并且通过单击图标我可以导航到另一个视图控制器。但是当我回到这个视图控制器时,仍然显示图标选项,但我需要在导航期间关闭滑动选项。

标签: swifttableview

解决方案


推荐阅读