您好我正在開發一個應用程序與自定義操作在tableview單元格。IOS目前ViewController並傳遞裏面的數據editActionsForRowAt
當用戶滑過單元格時。將會有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
}
}
}
人有一個理想是什麼? –
你在使用故事板嗎?即。你想繼續到新的視圖控制器?或者你是否在使用NIB或編程視圖控制器創建?我看到你有一個評論segue,所以我猜測前者? – Paulw11
嗨,是的。我有一個tableviewCell標籤的segue。試圖使用執行segue但信息不傳遞給新的Viewcontroller。信息只有通過正常點擊(不在刷卡編輯) –