我有一个取消和保存按钮,我可以在其中输入一个项目,当单击这些按钮时,它会展开到最后一个 Controller 。但是,当我添加选项卡栏 Controller 时,这些按钮不再起作用。有人可以向我解释这是为什么以及如何解决它吗?谢谢。附上代码。
@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()
}
}
最佳答案
“我添加一个标签栏 Controller ”是什么意思?很可能随着堆栈中的那个(不确定你把它放在哪里),presentingViewController is UINavigationController
逻辑不再成立,因为它现在是 UITabBarController。我会确保 presentingViewController
符合您的预期。
关于ios - 使用标签栏 Controller 展开和 popviewcontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39796557/