こんにちは、私はtableviewセルでカスタムアクションを持つアプリケーションを開発しています。IOS present ViewController内のViewControllerとデータを渡します。
ユーザーがセルをスワイプしたとき。 2つのアクションがあります:削除など私は、新しいviewControllerを提示し、オブジェクトデータを新しいviewControllerに渡すために、より多くのアクションを必要とします。それをどうやって達成するのですか?
私はこの
viewDidLoad
if let split = self.splitViewController {
let controllers = split.viewControllers
self.detailViewController = (controllers[controllers.count-1] as! UINavigationController).topViewController as? DetailViewController
}
とeditActionsForRowAt
方法
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let moreRowAction = UITableViewRowAction(style: .normal, title: "More", handler:{action, indexpath in
if let indexPath = self.tableView.indexPathForSelectedRow {
let object = self.fetchedResultsController.object(at: indexPath)
let controller = self.detailViewController!
controller.detailItem = object
controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem
controller.navigationItem.leftItemsSupplementBackButton = true
self.present(controller, animated: true, completion: nil)
}
// self.performSegue(withIdentifier: "showDetail", sender: self)
});
moreRowAction.backgroundColor = UIColor(red: 0.298, green: 0.851, blue: 0.3922, alpha: 1.0);
let deleteRowAction = UITableViewRowAction(style: .destructive, title: "Delete", handler:{action, indexpath in
self.deleteTapped(indexPath: indexPath as NSIndexPath)
});
return [deleteRowAction, moreRowAction];
}
削除機能の作業ではなく、より多くのアクションが動作しませんを使用して試してみました。そして助けは大いに感謝しています!おかげ
マイprepareforseuge
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetail" {
if let indexPath = self.tableView.indexPathForSelectedRow {
let object = self.fetchedResultsController.object(at: indexPath)
let controller = (segue.destination as! UINavigationController).topViewController as! DetailViewController
controller.detailItem = object
controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem
controller.navigationItem.leftItemsSupplementBackButton = true
}
}
}
送信者または選択した行のだろうか? –
あなたはストーリーボードを使用していますか?すなわち、あなたは新しいView Controllerにセグをしたいですか?または、NIBまたはプログラムによるビューコントローラの作成を使用していますか?私はあなたがコメントされたセグを見ているので、私は前者を推測していますか? – Paulw11
こんにちは。私は、tableviewCellラベルからsegueを持っています。 perform segueを使用しようとしましたが、情報は新しいViewControllerに渡されません。情報は通常のクリック(スワイプ編集ではありません)のときのみ合格です –