ios - 使用标签栏 Controller 展开和 popviewcontroller

标签 ios swift3

我有一个取消和保存按钮,我可以在其中输入一个项目,当单击这些按钮时,它会展开到最后一个 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/

相关文章:

ios - 在回调中以编程方式推送 View ,SwiftUI

objective-c - UITabBarController 中的 View 在内存警告后消失

ios - 在 UITableView 中设置自定义标题 View

ios - UIImageView 重复更新失败

ios - 使用 Swift 3 的 DynamoDB 中的保留关键字 ExpressionAttributeValues

swift - 如何在选择一行后隐藏tableView

swift - 如何每 (x) 秒从数组中获取随机字符串 (SWIFT 3)(SPRITEKIT)

ios - Google Analytics 链接器错误。找不到 -lGGLAnalytics 的库

ios - 使用 Xcode 9 和 AES 解密的 CryptoSwift

ios - 替换数组的 indexOf(_ :) method in Swift 3