ios - Swift 不平衡调用开始/结束外观转换

标签 ios swift uiviewcontroller uiimagepickercontroller

这个问题困扰了我一段时间。我在 UITabBarController 中有一个 UISplitViewController。主视图是一个 TableView。当我点击一个单元格时,我会调出一个非常基本的 View Controller ,其中只有一个 UIButton 居中。这是 View Controller 的代码:

class TestViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    @IBOutlet weak var button: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func buttonPressed(sender: AnyObject) {
        let pickerC = UIImagePickerController()
        pickerC.delegate = self

        pickerC.modalPresentationStyle = .Popover
        pickerC.popoverPresentationController?.sourceView = button as UIView
        pickerC.popoverPresentationController?.sourceRect = (button as UIView).bounds
        pickerC.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Any
        self.presentViewController(pickerC, animated: true, completion: nil)//4
    }

    func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
        self.dismissViewControllerAnimated(true, completion: nil)
    }

    func imagePickerControllerDidCancel(picker: UIImagePickerController) {
       self.dismissViewControllerAnimated(true, completion: nil)
    }
}

如果我单击取消或选择图像,选择器 Controller 将正确关闭。当我单击后退按钮返回到 TableView 时出现问题,我收到:

Unbalanced calls to begin/end appearance transitions for <TestViewController: 0x7fb882a72380>.

TestViewController 非常基础,那么为什么会发生这种情况?

最佳答案

如果您在上一个事务(动画)正在进行时尝试推送新的 View Controller ,则会出现此问题。因此,请检查您的代码流并进行适当的更改。检查您的解雇和呈现 View 动画。您可以使用属性 setAnimation 来“是/否”解决此问题

设置animated:NO,可能会解决你的问题

关于ios - Swift 不平衡调用开始/结束外观转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30061153/

相关文章:

ios - 无法在 Xcode 11 beta 中选择自定义字体?

iphone - 从另一个类创建父 View 的 subview 不起作用

ios - n 个 View Controller 或 n 个单元格

ios - 如何在 Storyboard 中显示弹出窗口的明确大小

ios - 当测试人员尝试下载应用程序时,Fabric 会导致错误

ios - iPhone 上的 AssetsLibrary 和音乐库

ios - 编译器不符合 UIImagePickerControllerDelegate 协议(protocol)

ios - AssumeRole - AWS iOS SDK 示例

ios - swift MapKit注释拖动状态图标

ios - 在 Swift 中将 unichar 附加到 NSMutableString