带标签栏控制器

时间:2016-09-30 17:03:49

标签: ios swift3

我有一个取消和保存按钮,我在其中输入一个项目,当单击这些按钮时,它会展开到最后一个控制器。但是,当我添加标签栏控制器时,这些按钮不再起作用。有人可以向我解释为什么这是以及如何解决它?谢谢。随附的是代码。

@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()
    }
}

1 个答案:

答案 0 :(得分:1)

你是什么意思"我添加一个标签栏控制器"?它可能与堆栈中的那个(不确定你放在哪里),presentingViewController逻辑不再成立,因为它现在是UITabBarController。我确保gitconfig是你期望的那样。