私のタイトルは、UITableView
の最初の行をスワイプしたいと言っているときに、ユーザがそれに来るときにViewController
となるでしょう。スワイプタッチなしのUITableViewCell
私のViewController
私は1つのUITableView
を持っています、各行には2つのボタン "More"と "Delete"アクションがあります。コードを見てください
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if (editingStyle == UITableViewCellEditingStyle.delete) {
}
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let deleteButton = UITableViewRowAction(style: .normal, title: "Delete") { action, index in
// Edit Button Action
}
deleteButton.backgroundColor = UIColor.red
let editButton = UITableViewRowAction(style: .normal, title: "Edit") { action, index in
// Delete Button Action
}
editButton.backgroundColor = UIColor.lightGray
return [deleteButton, editButton]
}
すべてがうまくいきます。しかし、エンドユーザが初めてこのViewController
に来たときに、スワイプアクションが利用可能であることを通知するので、彼らがそれを実行するように通知します。
質問:最初の行で自動的に左右にスワイプするにはどうすればよいですか?
私は何をしましたか?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let cell = posTblView.cellForRow(at: NSIndexPath(row: 0, section: 0) as IndexPath) as! POSUserTabelCell
UIView.animate(withDuration: 0.3, animations: {
cell.transform = CGAffineTransform.identity.translatedBy(x: -150, y: 0)
}) { (finished) in
UIView.animateKeyframes(withDuration: 0.3, delay: 0.25, options: [], animations: {
cell.transform = CGAffineTransform.identity
}, completion: { (finished) in
})
}
}
上記のコードでは、スワイプ/移動セルは機能していますが、「削除」と「詳細」ボタンは表示されません。
正しい方向に案内してください。
あなたのアプローチは左右にスワイプするのが正しいようです。しかし、組み込みのボタンをそのように強調表示できるかどうかはわかりません。確かにできることは、コンテンツの下にネイティブコントロールのようなUIViewを配置し、スワイプして表示し、セルから削除/非表示にすることです。この回答を確認してください:https://stackoverflow.com/questions/5301728/is-it-possible-to-programmatically-show-the-red-delete-button-on-a-uitableviewce – dirtydanee
この古いフレームワークを使用することができます: https://github.com/CEWendel/SWTableViewCell。次にviewdidappearに書き込みます。 [cell showRightUtilityButtonsAnimated:YES]; –
それでは、最初の行にスワイプを自動的にさせて、編集ボタンが見えるようにすることを目指しています。そうですか? –