0
我有一个取消和保存按钮,我在一个项目中输入,当它们点击这些按钮时它展开到最后一个控制器。但是,当我添加一个标签栏控制器这些按钮不再工作。有人可以向我解释为什么这是,以及如何解决它?谢谢。封闭的代码。展开和popviewcontroller与标签栏控制器
@IBAction func cancel2(_ sender: UIButton) {
// Depending on style of presentation (modal or push presentation), this view controller
// needs to be dismissed in two different ways.
let isPresentingInAddMealMode = presentingViewController is UINavigationController
if isPresentingInAddMealMode {
dismiss(animated: true, completion: nil)
}
else {
navigationController!.popViewController(animated: true)
}
}
//This method lets you configure a view controller before it's presented.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Check if object referenced by saveButton is the same object instance as sender.
if saveButton2 === sender as? UIButton {
let name = nameTextField.text ?? ""
let photo = photoImageView.image
//let rating = ratingControl.rating
// Set the meal to be passed to MealTableViewController after the unwind segue.
meal = Meal(name: name, photo: photo)
}
}
@IBAction func unwindToMealList(sender: UIStoryboardSegue) {
if let sourceViewController = sender.source as? MealViewController, let meal = sourceViewController.meal {
if let selectedIndexPath = tableView.indexPathForSelectedRow {
// Update an existing meal.
meals[selectedIndexPath.row] = meal
tableView.reloadRows(at: [selectedIndexPath], with: .none)
}
else {
// Add a new meal.
let newIndexPath = IndexPath(row: meals.count, section: 0)
meals.append(meal)
tableView.insertRows(at: [newIndexPath], with: .bottom)
}
// Save the meals.
saveMeals()
}
}
非常感谢! :3 –