我想滑动删除仅适用于case:0而不适用case:1-分段控件

时间:2018-10-13 15:47:00

标签: swift firebase uitableview uisegmentedcontrol

在我的应用程序中,我已滑动以在分段控件中删除,并且它通过显示两个不同的表视图来工作,但是我只想滑动以删除即可在我的情况0下工作,而不是在我的情况1下工作(因为1包含当前用户无法删除的其他用户数据。

我该怎么做?

这是我要删除并报告代码的滑动:

Console.Write("Morgan: " + i);

我尝试致电

@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

    let delete = UIContextualAction(style: .destructive, title: "Delete") { (action, view, nil) in
        Database.database().reference().child("messages").child(self.currentUserID!).child(self.message[indexPath.row].messageID).setValue([])                
    }

    let report = UIContextualAction(style: .destructive, title: "Report") { (action, view, nil) in

        let areUSureAlert = UIAlertController(title: "Are you sure you want to report?", message: "This will block this user from message you.", preferredStyle: UIAlertControllerStyle.alert)  
        areUSureAlert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action: UIAlertAction!) in

            Database.database().reference().child("messages").child(self.currentUserID!).child(self.message[indexPath.row].messageID).setValue([])

            let blockedPost = ["timestamp" : [".sv" : "timestamp"]]
            Database.database().reference().child("blocked").child(self.currentUserID!).child(self.message[indexPath.row].fromID).setValue(blockedPost)
        }))

        areUSureAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction!) in
            //dismiss(animated: true, completion: nil)
        }))

        self.present(areUSureAlert, animated: true, completion: nil)
     }
    report.backgroundColor = #colorLiteral(red: 0.9529411793, green: 0.8918681279, blue: 0, alpha: 1)

    return UISwipeActionsConfiguration(actions: [delete, report])
}

但是我认为我做错了。有人有想法吗?

1 个答案:

答案 0 :(得分:1)

滑动动作是动态创建的,因此请检查private lateinit var tableList: ArrayList<Tables> override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_daftar_meja) tableList = ArrayList() /*init RecyclerView*/ recyclerView_meja.layoutManager = GridLayoutManager(this, numberOfColumns(), GridLayoutManager.VERTICAL, false) recyclerView_meja.hasFixedSize() /*Set Adapter*/ dataAdapter = MejaAdapter(tableItem) { tableItemClicked() } recyclerView_meja.adapter = dataAdapter //Show list table val idCafe = user.cafeId getTableList(idCafe) } private fun getTableList(idCafe:String){ val apiService : Service = Client.getClient()!!.create(Service::class.java) apiService.getTable(idCafe).enqueue(object : Callback<Tables>{ override fun onResponse(call: Call<Tables>?, response: Response<Tables>?) { Log.i("IdMeja", "id : " + response?.body()) if (response != null && response.isSuccessful) { val listTable = response.body() if (listTable == null) { Toast.makeText(this@MainActivity, "Tidak ada meja", Toast.LENGTH_SHORT).show() } else{ tables = listTable // update list table Log.i("adapter", "$dataAdapter") dataAdapter.updateData(tableList) Toast.makeText(this@MainActivity, "hahaha$tables", Toast.LENGTH_SHORT).show() } } else{ Log.i("idCafe", " $idCafe") Toast.makeText(this@MainActivity, "Gagal dapat meja", Toast.LENGTH_SHORT).show() } } override fun onFailure(call: Call<Tables>?, t: Throwable?) { Log.i("fail",t.toString() ) Toast.makeText(this@MainActivity, "Gagal", Toast.LENGTH_SHORT).show() } }) } 中的selectedSegmentIndex。如果索引不是trailingSwipeActionsConfigurationForRowAt,则返回0,这表示不显示任何滑动操作。

nil